Response.RedirectLocation and 404 Page Status
Hi All,
On my page, if data is not found, i want to redirect my page to some customized page ( saying data not found)
with a status code 404 so that google dont crawl it.
I am using following code -
Response.Clear();
Response.Status =
"404 not found.";
Response.StatusCode = 404;
Response.AddHeader(
"Location", "error.htm");
Response.RedirectLocation=
"/error.htm";
It sets my page status to 404 but doesnt redirect to "error.htm",
however this code works for 301 & 302 redirection.
If anyone have idea, please help me out.
zirano lattPosted May 11, 2009, 3:19 AM
C#
throw new HttpException(404, "Data not found");
web.config
Niradhip ChakrabortyPosted May 4, 2009, 1:03 AM
You can make use of web.config file and complete the task.
<customErrors mode="RemoteOnly" defaultRedirect="Contents/CommonPage.aspx">
<error statusCode="403" redirect="Contents/CommonPage.aspx" />
<error statusCode="404" redirect="Contents/CommonPage.aspx" />
customErrors>