Application Error Get Current Page
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads
Mvc Global.asax Application_error
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the application_error mvc Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: application_error not firing Sign up How to get which page threw an exception to Application_error in aspx up vote 11 down vote favorite 1 I have a general exception handler, Application_error in my global.asax where I'm trying to isolate all the uncaught exceptions on all
Exceptionutility
my many pages. I don't want to use Page_error to catch exception because it's inefficient to call that on so many pages. So where in the exception can I find what page actually caused the exception? c# asp.net exception application-error share|improve this question edited Sep 8 '11 at 15:02 Lars A. Brekken 6,73631926 asked Dec 5 '08 at 16:40 user8456 183312 By the way, it's "Global.asax" –Mehrdad Afshari Dec 5 '08 at 16:51 add a comment| 2 Answers 2 active oldest
Application_error Web Api
votes up vote 20 down vote accepted HttpContext con = HttpContext.Current; con.Request.Url.ToString() share|improve this answer answered Dec 5 '08 at 16:47 jlew 7,3631949 add a comment| up vote 1 down vote Remember, the page is not (should not) always be the cause of the exception. It could just as easily be coming from another assembly - and if you don't have your logic in your codebehinds, it likely will be coming from another assembly. Don't get me wrong, it is great to know which page, from the aspect of saying X Page caused Y exception in Z assembly. share|improve this answer answered Dec 7 '08 at 13:24 Joseph Ferris 9,48533362 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged c# asp.net exception application-error or ask your own question. asked 7 years ago viewed 8010 times active 5 years ago Linked 1 How to capture the url of the page that threw an exception 0 Catch Error with Custome Error Page Related 1258Catch multiple exceptions at once?5Convert an exception into HTTP 404 response in the Application_Error6How to know if the request is ajax in asp.net in Application_Error()1Why “File does not e
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/how to access current page object when Application_Error from global... how to access current page object when Application_Error from global.asax asp.net error handling best practices ? RSS 6 replies Last post Mar 16, 2008 09:35 AM by ad_dc
Application_error Web Api 2
‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options global asax application error redirect Advanced Search Related Links GuidanceSamplesVideos Reply ad_dc Member 3 Points 79 Posts how to access current page object when Application_Error from global.asax ? Mar 10, 2008 12:34 PM|ad_dc|LINK hello there , http://stackoverflow.com/questions/344440/how-to-get-which-page-threw-an-exception-to-application-error-in-aspx I want to access current page opened when Application_Error event fired , is this possible ? my current Application_Error code is protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); HttpContext.Current.Session["Error"] = ex.Message; Response.Redirect("~/error.aspx", false); } but I want instate to access the current page to get something from it to save to log file ,[:'(] so anyone http://forums.asp.net/t/1231422.aspx?how+to+access+current+page+object+when+Application_Error+from+global+asax+ can provide help ?????? thanks a lot in advance Reply barryman9000 Participant 767 Points 601 Posts Re: how to access current page object when Application_Error from global.asax ? Mar 10, 2008 12:57 PM|barryman9000|LINK This will give you the name of the page where the error occured. Is that what you're looking for?HttpContext con = HttpContext.Current; con.Request.Url.ToString() "Don't sweat the petty things, and don't pet the sweaty things" - George Carlin Reply ad_dc Member 3 Points 79 Posts Re: how to access current page object when Application_Error from global.asax ? Mar 11, 2008 06:04 AM|ad_dc|LINK Well, thank you but I want to access the Page object itself not it's URL , so any ideas?? Reply ad_dc Member 3 Points 79 Posts Re: how to access current page object when Application_Error from global.asax ? Mar 11, 2008 08:26 AM|ad_dc|LINK Oh , ok I got it worked /*to get a reference to the current pagebeing requested at any point in your application * ,use the following code:*/ System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;but when I'm trying to change anything in it like that System.Exception objError = Server.GetLastError(); System.Web
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel https://msdn.microsoft.com/en-us/library/bb397417.aspx 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. MSDN Library http://codereview.stackexchange.com/questions/60759/error-handling-controllers-onexception-and-application-error MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development .NET Development Office development Online Services Open Specifications patterns & practices Servers application error and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Complete Example for Error Handlers Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 This application_error web api code example includes elements for both page-level and application-level exception handling. Code Example Files The example consists of the following files: Web.config Global.asax Default.aspx ExceptionUtility (to be put in the App_Code folder) GenericErrorPage.aspx HttpErrorPage.aspx Http404ErrorPage.aspx DefaultRedirectErrorPage.aspx Web.config The following example shows the Web.config file. The customErrors section specifies how to handle errors that occur with file types that are mapped to ASP.NET, such as .aspx, .asmx, and .ashx files. (In IIS 6.0 and in IIS 7.0 in classic mode, static content files such as .html and .jpg files are not mapped to ASP.NET.) The settings in the example customErrors section cause any unhandled HTTP 404 (file not found) errors to be directed to the Http404ErrorPage.aspx file. These HTTP 404 errors would occur if a request were made for an .aspx file, .asmx file, and so on and if the requested file did not exist. All other unhandled errors in ASP.NET files are directed to the DefaultRedirectErrorPage.aspx file. If static content files are not handled by ASP.NET, a request for
for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Code Review Questions Tags Users Badges Unanswered Ask Question _ Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Error Handling - Controller's OnException and Application_Error up vote 11 down vote favorite 7 I'm pretty new to MVC. Below is the code that I have added to an existing MVC 5 application. The code is using log4net to log any run-time error/exception. NOTE: I could override OnException() in MVC filter "HandleErrorAttribute" but I preferred to have this functionality in my custom Controller base class. Can anyone please review and provide feedback? BaseController.cs public class BaseController: Controller { private log4net.ILog logger; protected override void OnException(ExceptionContext filterContext) { //Log error logger = log4net.LogManager.GetLogger(filterContext.Controller.ToString()); logger.Error(filterContext.Exception.Message, filterContext.Exception); //If the request is AJAX return JSON else redirect user to Error view. if (filterContext.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest") { //Return JSON filterContext.Result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { error = true, message = "Sorry, an error occurred while processing your request." } }; } else { //Redirect user to error page filterContext.ExceptionHandled = true; filterContext.Result = this.RedirectToAction("Index", "Error"); } base.OnException(filterContext); } } HomeController.cs public class HomeController : BaseController { ... } Global.asax.cs public class MvcApplication : System.Web.HttpApplication { private static readonly ILog log = LogManager.GetLogger(typeof(MvcApplication)); protected void Application_Error(object sender, EventArgs e) { //Log exception Exception exception = Server.GetLastError(); log.Error(exception); //Clear error from response stream Response.Clear(); Server.ClearError(); //Redirect user Context.Server.TransferRequest("~/Error/"); } ... } For displaying errors, I have a basic ErrorController.cs with just Index() Action along with its associated Error/Index.cshtml. Some blogs suggests different error pages for different type of errors (such as 404 error). Do I need to handle them