What I am trying to do is when a user of my site is no longer exist, I redirect them to a Usererror.aspx page after doing a database look up via a redirect. However, I wish for this page to return a 404 status with Response.StatusCode=404 so I am not penalized
by seach engines, in particular Google. When I place this piece of code in the Usererror.aspx page it redirects to my customerror page.
Another thing I tried to get the Usererror.aspx page to emit a 404 error was to redirect to that page from the actual 404 page via a server.transfer. However, it only worked on the server. Off the server, it does not redirect.
What I am trying to do is when a user of my site is no longer exist, I redirect them to a Usererror.aspx page after doing a database look up via a redirect. However, I wish for this page to return a 404 status with Response.StatusCode=404 so I am not penalized
by seach engines, in particular Google. When I place this piece of code in the Usererror.aspx page it redirects to my customerror page.
Another thing I tried to get the Usererror.aspx page to emit a 404 error was to redirect to that page from the actual 404 page via a server.transfer. However, it only worked on the server. Off the server, it does not redirect.
Hi SuperRom,
You can handle Error Code 404 in following way
There are three places in ASP.NET to define what happens to these unhandled errors.
In the web.config file's customErrors section.
In the global.asax file's Application_Error sub.
On the aspx or associated codebehind page in the Page_Error sub.
The actual order of error handling events is as follows:
On the Page itself, in the Page_Error sub (this is default, you can name it anything because it specificed Handles MyBase.Error)
You can set the error page at web.config file so whenever that error code occur your application redirect it to your mentioning page. Add these lines in your <system.web> tag in web.config file.
Hey Moderators, why was this post marked as answered when I did not do it. I was the one who asked the question, therefore, I should be the one to select answered or not.
Anyhow, I found the solution by doing the following steps:
SuperRom
Member
179 Points
240 Posts
What would cause Response.Statuscode=404 to cause an error
Dec 29, 2012 10:58 PM|LINK
What I am trying to do is when a user of my site is no longer exist, I redirect them to a Usererror.aspx page after doing a database look up via a redirect. However, I wish for this page to return a 404 status with Response.StatusCode=404 so I am not penalized by seach engines, in particular Google. When I place this piece of code in the Usererror.aspx page it redirects to my customerror page.
Another thing I tried to get the Usererror.aspx page to emit a 404 error was to redirect to that page from the actual 404 page via a server.transfer. However, it only worked on the server. Off the server, it does not redirect.
matifnadeem
Contributor
4928 Points
1145 Posts
Re: What would cause Response.Statuscode=404 to cause an error
Jan 02, 2013 10:42 AM|LINK
Hi SuperRom,
You can handle Error Code 404 in following way
There are three places in ASP.NET to define what happens to these unhandled errors.
The actual order of error handling events is as follows:
Follow this link to resolve your issue
Let me know if any query remains.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
matifnadeem
Contributor
4928 Points
1145 Posts
Re: What would cause Response.Statuscode=404 to cause an error
Jan 02, 2013 10:45 AM|LINK
Hi again,
You can set the error page at web.config file so whenever that error code occur your application redirect it to your mentioning page. Add these lines in your <system.web> tag in web.config file.
<customErrors mode="On" defaultRedirect="error.htm"> <error statusCode="500" redirect="CustomerError500.aspx"/> <error statusCode="401" redirect="CustomerAccessDenied.aspx"/> <error statusCode="404" redirect="CustomerPageNotFound.htm"/> <error statusCode="403" redirect="noaccessallowed.htm"/> </customErrors>Let me know if any query remains.
Cheers
M Atif Nadeem
Mark as Answer if you got right thing
Read my blog | Follow me on LinkedIn
SuperRom
Member
179 Points
240 Posts
Re: What would cause Response.Statuscode=404 to cause an error
Jan 09, 2013 12:13 AM|LINK
Hey Moderators, why was this post marked as answered when I did not do it. I was the one who asked the question, therefore, I should be the one to select answered or not.
Anyhow, I found the solution by doing the following steps:
1. Remove the 404 Error within customerrors
2. Entering the code below
Response.StatusCode = 404
Response.TrySkipIisCustomErrors = True