Httpcontext Error
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 the name 'httpcontext' does not exist in the current context company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Httpcontext Does Not Exist In The Current Context Class Library
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million system.web.httpcontext not found programmers, just like you, helping each other. Join them; it only takes a minute: Sign up HttpContext.Error vs HttpContext.Server.GetLastError() up vote 11 down vote favorite 1 Are there any practical differences between these two ways of getting the name 'response' does not exist in the current context an exception for the current asp.net request? MSDN says HttpContent.Error returns the FIRST error while GetLastError() is evidently the last error, but I can't seem to tell any difference in use. Which one is the cannon method for error logging? asp.net share|improve this question asked Apr 11 '09 at 17:30 Craig Quillen 1,08221329 add a comment| 1 Answer 1 active oldest votes up vote 17 down vote accepted They're the same: HttpContext.Error returns
Httpcontext.current Is Null
the first error. HttpContext.Server returns an instance of the HttpServerUtility class, which provides convenience wrappers for HttpContext, including HttpContext.Server.GetLastError(), which returns HttpContext.Error (verified using Reflector). share|improve this answer answered Apr 11 '09 at 17:36 Shog9♦ 108k28184217 Additionally GetLastError is checking firstly for the error on the HttpContext, and then the HttpApplication.. this is because a HttpServerUtility can be created with a HttpApplication instead of a HttpContext.. -- overall, it should make no difference, but stick to GetLastError probably. –meandmycode Apr 11 '09 at 17:43 @meandmycode: while HttpServerUtility is able to retrieve the error from HttpApplication, the instance returned from HttpContext does not. (HttpApplication.Server will give you one that does) –Shog9♦ Apr 11 '09 at 17:57 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 asp.net or ask your own question. asked 7 years ago viewed 2097 times active 7 years ago Blog Stack Overflow Podcast #91 - Can You Stump Nick Craver? Linked 3 application_error Server or HttpContext.Current.Server
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies the name does not exist in the current context c# of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the 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 http://stackoverflow.com/questions/740482/httpcontext-error-vs-httpcontext-server-getlasterror minute: Sign up How to get information about error from HttpContext in WCF services up vote 1 down vote favorite I need to log information about contract invocation (following info: request, client address, invoked method name) when client passes invalid SOAP request to WCF service contract (NetDispatcherFaultException is thrown). I can get all needed info from HttpContext object in Global class (Global.asax), http://stackoverflow.com/questions/30665819/how-to-get-information-about-error-from-httpcontext-in-wcf-services for example in Application_EndRequest event handler. My code (it's work fine): protected void Application_EndRequest(object sender, EventArgs e) { const string InfoMessageTemplate = "Client [address='{0}'] called following contract: '{1}'. Request data: {2}"; var currentRequest = Context.Request; var calledContract = currentRequest.Headers["SOAPAction"] ?? string.Empty; string clientAddress = currentRequest.UserHostAddress; var requestInputStream = new StreamReader(currentRequest.InputStream); string requestString = HttpUtility.UrlDecode(requestInputStream.ReadToEnd()); Logger.Info(InfoMessageTemplate, clientAddress, calledContract, requestString); } But I don't want to log all requests, only when NetDispatcherFaultException is thrown. I suggested that HttpContext.Error and/or HttpContext.AllErrors properties should contain information about occurred exception but they are always empty (equal NULL). I have implemented IErrorHandler (global exception handling) and connected it to my WCF service. HandleError method is called each time when any error occurred. But I cannot get access to HttpContext inside this method (because this method executed in another thread) and I cannot get all needed info for logging. So, I think my last hope is event handlers in Global.asax. If I could to get information about occurred error it would have helped me a lot. Can I do this somehow? c# wcf logging httpcontext share|improve this question asked
Latest Articles Latest Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip http://www.codeproject.com/Articles/600466/ASP-NETplusApplicationplusErrorplusHandling Post your Blog quick answersQ&A Ask a Question about this article Ask http://forums.asp.net/t/1523848.aspx?HttpContext+Current+Error a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> does not ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase does not exist Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Articles » Web Development » ASP.NET » General ArticleBrowse CodeStatsRevisions (9)Alternatives Comments (37) Add your ownalternative version Tagged as HTMLC#VS2013ASP.NET Stats 112.7K views2.7K downloads90 bookmarked Posted 30 May 2013 ASP.NET Application Error Handling Daniel Miller, 26 Jan 2015 CPOL 4.95 (37 votes) 1 2 3 4 5 4.95/5 - 37 votesμ 4.95, σa 1.05 [?] Rate this: Please Sign up or sign in to vote. Application error handling in ASP.NET Download demo - 269.4 KB Introduction When an unhandled exception occurs in my application, I want my application to give the user a "graceful" response. Regardless of the error, I do not want the user to see an unfriendly techni
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Getting Started/HttpContext.Current.Error HttpContext.Current.Error RSS 4 replies Last post Feb 10, 2010 06:02 AM by BBuzzi ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply BBuzzi Member 101 Points 110 Posts HttpContext.Current.Error Feb 09, 2010 02:06 PM|BBuzzi|LINK Hi, I'm overwritingsome code that handles callbacksso I can get exceptions logged in every possible way... But callbacks are called very often on my webapp. What I'd like to know is what is the performance cost to call HttpContext.Current.Error very often. Could somebody explain or point me a way to get this info?! What I know so far is that it will return null if there's no exception on the webapp, but to return null, calling this will cost the same as throwing/creating an Exception (which has asignificant performance impact)?! Thanks for the help! Thanks! Bruno Buzzi brunobuzzi@gmail.com Reply d4daud Participant 1529 Points 490 Posts Re: HttpContext.Current.Error Feb 10, 2010 01:34 AM|d4daud|LINK http://stackoverflow.com/questions/290927/how-much-computation-is-behind-a-httpcontext-current-call Daud Reply vijayst Star 10440 Points 3208 Posts Re: HttpContext.Current.Error Feb 10, 2010 01:53 AM|vijayst|LINK have you tried applicaiton_error on global.asax or page_error for handling these errors. these are good place to handle exceptions and clearing the error queue once logged / handled. Vijay My blog: http://vijayt.com Free C# code to copy-paste Reply BBuzzi Member 101 Points 110 Posts Re: HttpContext.Current.Error Feb 10, 2010 05:55 AM|BBuzzi|LINK Hi Daud, Ihave restricted access to the internethere, so the link couldn't help... =/ Thanks! Thanks! Bruno Buzzi brunobuzzi@gmail.com Reply BBuzzi Member 101 Points 110 Posts Re: HttpContext.Current.Error Feb 10, 2010 06:02 AM|BBuzzi|LINK Hi Vijay, In my own HttpModule the exception is logged on the OnError event. But on the third party handler the exceptionis cons