tag:blogger.com,1999:blog-602850767119300869.post8527957612755063875..comments2023-10-03T11:09:06.474-04:00Comments on Web.NET: Search Engine Friendly Error HandlingAThttp://www.blogger.com/profile/03810972326430206042noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-602850767119300869.post-51742430293996552112012-03-17T04:59:19.935-04:002012-03-17T04:59:19.935-04:00Hello Sir,
I use that Piece of code in my web.con...Hello Sir,<br /><br />I use that Piece of code in my web.config file code is<br /><br />for e.g i run<br />http://www.mysite.com/contact.aspx to http://www.mysite.com/con.aspx<br /><br />it works fine but same i run http://www.mysite.com/contact.html it genrate the 403 error status code instead of 404<br /><br />Please help me regarding thatpranayhttps://www.blogger.com/profile/14692280186288331092noreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-86932146628896254352010-01-15T02:45:57.744-05:002010-01-15T02:45:57.744-05:00Good article! Was thinking about blogging on this ...Good article! Was thinking about blogging on this myself, but looks like you cover it pretty well ;)Jef Claeshttps://www.blogger.com/profile/17313599911430422160noreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-2289584745633228082009-09-17T10:14:48.527-04:002009-09-17T10:14:48.527-04:00Ricardo, I've seen the same behavior too. I...Ricardo, I've seen the same behavior too. I've been trying to figure out the reason and even tried to debug .NET code but couldn't get to the problem. So the only solution I can suggest in your case is to not use ASP.NET custom error handling at all. Instead configure your own custom error handling in global.asax. I should work at least it works for me.AThttps://www.blogger.com/profile/03810972326430206042noreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-22303995190690129392009-09-09T10:51:48.718-04:002009-09-09T10:51:48.718-04:00Hi!
I tried the technique described but having so...Hi!<br /><br />I tried the technique described but having some trouble getting it to work.<br /><br />My web.config has:<br /><br />customerrors mode="RemoteOnly" defaultredirect="~/DefaultErrorPage.aspx" redirectmode="ResponseRewrite"<br /><br />Then in my ErrorPage's Page_Load() I have:<br /><br />If Not Server.GetLastError() Is Nothing Then<br /> Dim ex As Exception = Server.GetLastError().GetBaseException<br /> If Not ex Is Nothing Then<br /> 'Send email to webmaster, save in log table<br /> End If<br />End If<br /><br />With redirectMode="ResponseRewrite" the custom error page (DefaultErrorPage.aspx) is not displayed... but if I replace the aspx by a static html then it works.<br /><br />Additionaly, if I use redirectMode="ResponseRedirect" instead, the custom error page (DefaultErrorPage.aspx) is displayed, but in this case I cannot get access to the error/exception details (Server.GetLastError() is null).<br /><br />Perhaps this is one of the cases, as you mentioned, where we cannot "use the new redirectMode attribute in the .config file (older framework, application specifics, etc.)" and must use Application_Error in global.asax instead.<br /><br />Any thought on this? Thanks,<br /><br />Ricardo.Unknownhttps://www.blogger.com/profile/01127642878386389662noreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-25674632699159368442009-01-22T12:00:00.000-05:002009-01-22T12:00:00.000-05:00To IDisposable:If you use "as" the casting operati...To IDisposable:<BR/><BR/>If you use "as" the casting operation potentially may return null without raising an exception. In this case one should always check for null before accessing an object's member. (Even Visual Studio will warn you about potential null value.)<BR/><BR/>In my code on the contrary I use "is" first to check whether the Exception object is in fact an instance of HttpException class. Therefore direct casting is totally safe and does not require additional checks.AThttps://www.blogger.com/profile/03810972326430206042noreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-52967873326453287962009-01-16T15:06:00.000-05:002009-01-16T15:06:00.000-05:00Nice, one minor niggle: Exception ex = ...Nice, one minor niggle:<BR/> Exception ex = Server.GetLastError();<BR/> if (ex is HttpException)<BR/> {<BR/> httpCode = ((HttpException) ex).GetHttpCode();<BR/> }<BR/><BR/>Should be written using <B>as</B> instead:<BR/><BR/> int httpCode = 500;<BR/> Exception hex = Server.GetLastError() as HttpException;<BR/> if (hex != null)<BR/> {<BR/> httpCode = hex.GetHttpCode();<BR/> }<BR/> Response.StatusCode = httpCode;Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-602850767119300869.post-46430265950136253242009-01-16T13:18:00.000-05:002009-01-16T13:18:00.000-05:00Great article!I was thinking about throwing 404s w...Great article!<BR/>I was thinking about throwing 404s when some content is not found for some time... Now you convinced me!Anonymousnoreply@blogger.com