Asp.net Get Error Statuscode
Contents |
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Getting Started/Get Status Code of error Get Status Code of error [Answered]RSS 6 replies Last
Asp.net Error Handling
post Sep 02, 2008 10:52 PM by Zong-Qing Li - MSFT asp.net custom error ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads asp.net custom error page Support Options Advanced Search Reply Niall20 Member 35 Points 991 Posts Get Status Code of error Aug 29, 2008 05:02 AM|Niall20|LINK When an error occurs on my site,
Asp.net Mvc Custom Error Page
I redirect users to a error page, like so in the web.config "RemoteOnly" defaultRedirect="Error.aspx /"> Is there anyway in Error.aspx to find the error status code (eg 404 etc)? I want to display an error message based on the status code. Reply G0ggy Member 659 Points 297 Posts Re: Get Status Code of error Aug 29,
Tryskipiiscustomerrors
2008 07:01 AM|G0ggy|LINK Have a read of this article: http://support.microsoft.com/kb/308132 It explains the different methods for custom error reporting. Remember to mark as answer the solution which helped you. Reply ruckfules Member 745 Points 158 Posts Re: Get Status Code of error Aug 29, 2008 07:01 AM|ruckfules|LINK Hi, you can use like follows;
pages, chances are your site is returning the incorrect HTTP status codes for the errors that your users are experiencing (hopefully as few as possible!). Sure, your users see a error page design pretty error page just fine, but your users aren’t always flesh and blood. Search
Httpexception
engine crawlers are also your users (in a sense), and they don’t care about the pretty pictures and funny one-liners customerrors mode on your error pages; they care about the HTTP status codes returned. For example, if a request for a page that was removed consistently returns a 404 status code, a search engine will remove http://forums.asp.net/t/1312621.aspx?Get+Status+Code+of+error it from its index. However, if it doesn’t and instead returns the wrong error code, the search engine may leave the page in its index. This is what happens if your non-existent pages don't return the correct status code! Unfortunately, ASP.NET custom error pages don’t return the correct error codes. Here’s your typical ASP.NET custom error page configuration that goes into the Web.config:
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community https://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.statuscode(v=vs.110).aspx Magazine Forums Blogs Channel 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. System.Net HttpWebResponse Class HttpWebResponse Properties HttpWebResponse Properties StatusCode Property StatusCode Property StatusCode Property CharacterSet Property ContentEncoding Property ContentLength Property ContentType Property Cookies custom error Property Headers Property IsMutuallyAuthenticated Property LastModified Property Method Property ProtocolVersion Property ResponseUri Property Server Property StatusCode Property StatusDescription Property SupportsHeaders Property 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. HttpWebResponse.StatusCode Property .NET asp.net custom error Framework (current version) Other Versions Visual Studio 2010 .NET Framework 4 Silverlight Visual Studio 2008 .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 .NET Framework 1.1 Gets the status of the response.Namespace: System.NetAssembly: System (in System.dll)Syntax C#C++F#VB Copy public virtual HttpStatusCode StatusCode { get; } Property Value Type: System.Net.HttpStatusCodeOne of the HttpStatusCode values.Exceptions Exception Condition ObjectDisposedExceptionThe current instance has been disposed. RemarksThe StatusCode parameter is a number that indicates the status of the HTTP response. The expected values for status are defined in the HttpStatusCode class.ExamplesThe following example uses StatusCode to verify that the status of the HttpWebResponse is OK. C#C++VB Copy public static void GetPage(String url) { try { // Creates an HttpWebRequest for the specified URL. HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); // Sends the HttpWebRequest and waits for a response. HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); if (myHttpWebResponse.StatusCode == HttpStatusCode.OK) Console.WriteLine("\r\nResponse Status Code is OK and StatusDescription is: {0}", myHttpWebResponse.StatusDescription); // Releases the resources of