How To Get Error Status Code In Asp.net
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 pretty error page just fine, but your users aren’t always flesh and blood. Search engine crawlers are also your users (in a sense), and they don’t care about the pretty pictures and funny one-liners 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 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:
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 with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack http://www.digitallycreated.net/Blog/57/getting-the-correct-http-status-codes-out-of-asp.net-custom-error-pages 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: Sign up Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse up vote 171 down vote favorite 27 I am trying to get http://stackoverflow.com/questions/1330856/getting-http-status-code-number-200-301-404-etc-from-httpwebrequest-and-ht the HTTP status code number from the HttpWebResponse object returned from a HttpWebRequest. I was hoping to get the actual numbers (200, 301,302, 404, etc.) rather than the text description. ("Ok", "MovedPermanently", etc.) Is the number buried in a property somewhere in the response object? Any ideas other than creating a big switch function? Thanks. HttpWebRequest webRequest = (HttpWebRequest)WebRequest .Create("http://www.gooogle.com/"); webRequest.AllowAutoRedirect = false; HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); //Returns "MovedPermanently", not 301 which is what I want. Console.Write(response.StatusCode.ToString()); c# .net http httpwebrequest share|improve this question edited Nov 15 '12 at 15:03 SteveC 4,035135198 asked Aug 25 '09 at 20:39 James Lawruk 15.4k128896 add a comment| 4 Answers 4 active oldest votes up vote 226 down vote accepted Console.Write((int)response.StatusCode); HttpStatusCode (the type of response.StatusCode) is an enumeration where the values of the members match the HTTP status codes, e.g. public enum HttpStatusCode { ... Moved = 301, OK = 200, Re
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 http://forums.asp.net/t/1312621.aspx?Get+Status+Code+of+error [Answered]RSS 6 replies Last post Sep 02, 2008 10:52 PM https://www.exceptionnotfound.net/http-status-codes-in-asp-net-web-api-a-guided-tour/ by Zong-Qing Li - MSFT ‹ Previous Thread|Next Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply Niall20 Member 35 Points 991 Posts Get Status Code of error Aug 29, 2008 05:02 how to AM|Niall20|LINK When an error occurs on my site, 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 how to get 659 Points 297 Posts Re: Get Status Code of error Aug 29, 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;
Performance Benchmarking Using HTTP Methods (GET, POST, PUT, etc) in Web API Designing a Workflow Engine Database The Daily Design Pattern Diary of a Death March HTTP Status Codes in ASP.NET Web API - A Guided Tour December 22nd, 2015 asp.net · tutorials · original-fiction · web-api · http · guided-tour Good morning everyone, and welcome to the new HTTP Status Codes in ASP.NET Web API tour here at Exception Not Found! My name is Reggie, and I'll be your tour guide today. Those of you who have taken our Exception Handling tour, welcome back! For those of you who are new to our facility, thank you for visiting us. WikCon UK 2012 Science Museum tour 6 from Wikimedia, used under license First off, I'd like to introduce my brilliant assistant Postman, who will be assisting me on this tour. Also assisting us will be Nathan, and he'll be doing whatever I need him to, and he better be grateful, this is his last chance, that little... As I said, Nathan will be assisting us, since we have such a large group. This tour moves fast, so please keep up. Today, we're going to take a look around at the variety of status codes we can return from our Web API applications. Step right this way, stay together, and let's learn about what HTTP status codes are and how we use them in our ASP.NET Web API projects. The Types of Status Codes HTTP implements a wide variety of status codes, which are grouped into five categories. The five categories are distinguished by the code's first number, like so: 1XX Codes: Informational codes. Rarely used in modern web apps. 2XX Codes: Success codes. Tells the client that the request succeeded. 3XX Codes: Redirect codes. Tells the client that they may need to redirect to another location. 4XX Codes: Client Error codes. Tells the client that something was wrong with what it sent to the server. 5XX Codes: Server Error codes. Tells the client that something went wrong on the server's side, so that the client may attempt the request again, possibly at a later time. ASP.NET Web API can return any of those codes, though the more common ones have simpler return methods. Up next, we will show how we can determine what the proper code is to return from our action methods. This way, please. Sel