Click here to Skip to main content
15,887,476 members
Home / Discussions / ASP.NET
   

ASP.NET

 
SuggestionRe: Datalist onitemcommand Pin
Richard Deeming26-Aug-14 2:01
mveRichard Deeming26-Aug-14 2:01 
GeneralRe: Datalist onitemcommand Pin
Otekpo Emmanuel26-Aug-14 4:45
Otekpo Emmanuel26-Aug-14 4:45 
Questionrelated to final year projects Pin
Member 1067942624-Aug-14 0:52
Member 1067942624-Aug-14 0:52 
AnswerRe: related to final year projects Pin
Richard MacCutchan24-Aug-14 4:50
mveRichard MacCutchan24-Aug-14 4:50 
GeneralRe: related to final year projects Pin
aarif moh shaikh12-Sep-14 20:59
professionalaarif moh shaikh12-Sep-14 20:59 
QuestionIBM DB2 for As400 OLE DB Provider Pin
giocot23-Aug-14 0:55
giocot23-Aug-14 0:55 
AnswerRe: IBM DB2 for As400 OLE DB Provider Pin
jkirkerx24-Aug-14 10:32
professionaljkirkerx24-Aug-14 10:32 
QuestionMoving duplicated 'return View("Index");' statments out of several multi exception catch blocks into a single block of code outside of the try/catch conditions Pin
Stephen Holdorf22-Aug-14 14:49
Stephen Holdorf22-Aug-14 14:49 
This is very hard to explain and probably even more difficult to solve. What I am doing is removing all error logging from the MVC controllers into a single log statment in the Global.asax Application_Error event. This is the problem I am faced with. To do this I am using a method like below in a controller I refactored:

try
{

tg.updateUpproverDetails(app.RequestID, reg["RoleId"], reg["ServiceId"], reg["RegionId"], reg["MTFSiteName"]);

ViewBag.RegionId = new SelectList(uRegions, "RegionID", "RegionName", reg["RegionId"]);

ViewBag.ServiceId = new SelectList(uServices, "MTFServiceID", "MTFServiceName", reg["ServiceId"]);
ViewBag.RoleId = new SelectList(uRoles, "ABACUSUserRoleID", "UserRole", reg["RoleId"]);

List<string> mtflist = new List<string>();

string[] yu = reg["MTFSiteName"].Split(',');

if (yu != null)
{
foreach (var x in yu.ToList<string>())
{
mtflist.Add(x);
}
}

ViewBag.MtfId = new MultiSelectList(uMtfs, "MTFSiteID", "MTFSiteName", mtflist);

return View(app);

}
catch (Exception e)
{
e.Data["ErrorMsg"] = "General Unhandled Exception";
e.Data["Location"] = "UpdateUpproverDetails procedure in AdminController";

if (e is DataException)
{
e.Data["ErrorMsg"] = "Data Exception";
e.Data["Location"] = "UpdateUpproverDetails procedure in AdminController";
}
else if (e is NullReferenceException)
{
e.Data["ErrorMsg"] = "Null Reference Exception";
e.Data["Location"] = "UpdateUpproverDetails procedure in AdminController";
}
throw e;
}

As you can see if no exceptions occur then the 'return View(app);' does it post and displays ther view. If however; there is an except it is trapped in a single catch block and re-thrown to the Global.asax Application_Error event for loggin. Now this works.

Now for the problem controller's try/catch block. Below is the following code:

try
{
response = client.GetAsync("Registration?user=" + Username).Result;

responseBodyAsText = response.Content.ReadAsStringAsync().Result;

if (responseBodyAsText.Equals("true"))
{
usercred.Newpassword = "";
usercred.Currentpassword = Password;
usercred.Username = Username;

return View("Change", usercred);

}

else
{


/////LOGIN USER
string passurl = System.Web.HttpUtility.UrlEncode(Password);
response = client.GetAsync("Registration?username=" + Username + "&password=" + passurl + "&edi=" + "" + "&isEdi=" + false).Result;
responseBodyAsText = response.Content.ReadAsStringAsync().Result;
statuses = JObject.Parse(responseBodyAsText);

DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(UserCred));

using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(statuses.ToString())))
{
usercred = (UserCred)serializer.ReadObject(ms);
}

}

}
catch (ArgumentOutOfRangeException e)
{
ViewBag.result = "NotAuthenticated";
log.Info("The size specified is less than or equal to zero. Login/Password for user failed " + e.ToString());
return View("Index");
}

catch (ObjectDisposedException e)
{
ViewBag.result = "NotAuthenticated";
log.Info("The current instance has been disposed. Login/Password for user failed " + e.ToString());
return View("Index");
}

catch (InvalidOperationException e)
{
ViewBag.result = "NotAuthenticated";
log.Info("An operation has already been started on the current instance. Login/Password for user failed " + e.ToString());
return View("Index");
}

catch (ArgumentNullException e)
{
ViewBag.result = "NotAuthenticated";
log.Info("Login/Password for user failed " + e.ToString());
return View("Index");
}
catch (Exception e)
{
ViewBag.result = "NotAuthenticated";
log.Info("Login/Password for user failed " + e.ToString());
throw;
}
}

Session["userData"] = usercred;
Session.Add("Authenticated", "True");

return RedirectToAction("Index", "Home", usercred);

}

Here you can see that in each catch statment the logging is done, not in the Application_Error event, but in the catch statment itself. Also in each catch statment a specific 'return View("Index");' is called and a return RedirectToAction("Index, "Home") is called at the bottom.

I tried the following and the exception is never thrown. Can anyone help?

catch (Exception e)
{
ViewBag.result = "NotAuthenticated";

return View("Index")

throw e;
}

Session["userData"] = usercred;
Session.Add("Authenticated", "True");

return RedirectToAction("Index", "Home", usercred);

}

}
AnswerRe: Moving duplicated 'return View("Index");' statments out of several multi exception catch blocks into a single block of code outside of the try/catch conditions Pin
onelopez22-Aug-14 16:21
onelopez22-Aug-14 16:21 
QuestionOne on one chat application Pin
Otekpo Emmanuel21-Aug-14 22:39
Otekpo Emmanuel21-Aug-14 22:39 
AnswerRe: One on one chat application Pin
Anurag Gandhi22-Aug-14 3:32
professionalAnurag Gandhi22-Aug-14 3:32 
QuestionSql delete statement Pin
Otekpo Emmanuel21-Aug-14 5:20
Otekpo Emmanuel21-Aug-14 5:20 
AnswerRe: Sql delete statement Pin
ZurdoDev21-Aug-14 7:36
professionalZurdoDev21-Aug-14 7:36 
AnswerRe: Sql delete statement Pin
Anurag Gandhi22-Aug-14 3:35
professionalAnurag Gandhi22-Aug-14 3:35 
QuestionSql delete statement Pin
Otekpo Emmanuel21-Aug-14 4:16
Otekpo Emmanuel21-Aug-14 4:16 
AnswerRe: Sql delete statement Pin
Richard Deeming21-Aug-14 4:20
mveRichard Deeming21-Aug-14 4:20 
GeneralRe: Sql delete statement Pin
PIEBALDconsult21-Aug-14 4:23
mvePIEBALDconsult21-Aug-14 4:23 
QuestionIssues on the IIS Deployment on an ASP.NET 4.5 Pin
Vimalsoft(Pty) Ltd21-Aug-14 1:43
professionalVimalsoft(Pty) Ltd21-Aug-14 1:43 
AnswerRe: Issues on the IIS Deployment on an ASP.NET 4.5 Pin
ZurdoDev21-Aug-14 8:04
professionalZurdoDev21-Aug-14 8:04 
AnswerRe: Issues on the IIS Deployment on an ASP.NET 4.5 Pin
jkirkerx21-Aug-14 9:30
professionaljkirkerx21-Aug-14 9:30 
GeneralRe: Issues on the IIS Deployment on an ASP.NET 4.5 Pin
Vimalsoft(Pty) Ltd21-Aug-14 9:38
professionalVimalsoft(Pty) Ltd21-Aug-14 9:38 
GeneralRe: Issues on the IIS Deployment on an ASP.NET 4.5 Pin
jkirkerx21-Aug-14 10:03
professionaljkirkerx21-Aug-14 10:03 
GeneralRe: Issues on the IIS Deployment on an ASP.NET 4.5 Pin
Vimalsoft(Pty) Ltd21-Aug-14 10:27
professionalVimalsoft(Pty) Ltd21-Aug-14 10:27 
QuestionString compare Pin
byka20-Aug-14 8:01
byka20-Aug-14 8:01 
AnswerRe: String compare Pin
Richard Deeming20-Aug-14 9:14
mveRichard Deeming20-Aug-14 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.