404錯(cuò)誤狀態(tài)碼是頁(yè)面找不到時(shí)才返回的一個(gè)告訴搜索引擎此頁(yè)面永久不存了,下面小編來(lái)給各位同學(xué)介紹一下404錯(cuò)誤狀態(tài)碼在asp代碼中如何實(shí)現(xiàn)吧。
asp中設(shè)置404狀態(tài)
代碼如下:
><%
Response.Status = "404 Not Found"
%>
ASP.NET設(shè)置404頁(yè)面
在404.aspx中加入代碼:
代碼如下:
>Response.Status = "404 Moved Permanently";
在 Global.asax 中加入下面的代碼:
代碼如下:
>protected void Application_Error(object sender, EventArgs e)
{
//在出現(xiàn)未處理的錯(cuò)誤時(shí)運(yùn)行的代碼
this.FileNotFound_Error();
}
/// <summary>
/// 404錯(cuò)誤處理
/// </summary>
private void FileNotFound_Error()
{
HttpException erroy = Server.GetLastError() as HttpException;
if (erroy != null && erroy.GetHttpCode() == 404)
{
Server.ClearError();
string path = "~/404.aspx";
Server.Transfer(path);
//Context.Handler = PageParser.GetCompiledPageInstance(path, Server.MapPath(path), Context);
}
}
更多信息請(qǐng)查看IT技術(shù)專欄