greatking 2019-04-12
本文实例讲述了Asp.Net实现404页面与301重定向的方法。分享给大家供大家参考。具体实现方法如下:
从一种程度来讲301重定向与404页面没什么关系为什么我要拿到一起来讲来,因为都很简单实现,所在我就一起介绍一下了。
如何在 asp.net 中设置404页面的方法记录下来。
下边首先看看之前的设置方法,web.config文件中:
代码如下:
<configuration> <system.web> <customErrors mode="RemoteOnly" defaultRedirect="404.aspx"> </customErrors> </system.web> </configuration>
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
Response.Status = "404 Not Found";
}代码如下:
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.StatusCode = 301;
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","//www.jb51.net");
}希望本文所述对大家的asp.net程序设计有所帮助。