程序实现404报错以后,指向到404报错页面 当程序判断条件是真的时候,就报错,然后指向到404页面.我这里只是实现状态是404,自己定义的404页面,不能设置。iis里有自定义的404页面.if (a !=b){System.Web.HttpContext.Current.Response.Clear();System.Web.HttpContext.Current.Response.StatusCode = 404; System.Web.HttpContext.Current.Response.End(); } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在web.config中可以设置<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> web.config中设置<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="404" redirect="404.htm" /> </customErrors> <customErrors mode="RemoteOnly" defaultRedirect="Error.aspx"> <error statusCode="404" redirect="~/FileNotFound.htm" /></customErrors>protected void Application_Error(Object sender, EventArgs e) { string strStatus = Context.Response.StatusCode.ToString() ; Exception objErr = Server.GetLastError().GetBaseException(); string error = "发生异常页: " + Request.Url.ToString() + "<br>"; error += "异常信息: " + objErr.Message + "<br>"; Server.ClearError(); Application["error"] = error; Response.Redirect("ErrorPage.aspx"); } wuyq11,你好。页面 http://www.abc.com/user.aspx?id=123 当程序判断这个id不存在http://www.abc.com/404.htm当程序判断这个id不存在。就报404错误,并跳出404自定义页面,这样能实现吗?这样算不算是302跳转呢? 我的情况下是http://www.abc.com/user.aspx?id=123是正常可以打开的 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors>Web.Config ???????$' 不是一个有效名称 .Net+Sql2005 实现图片批量上传 base64 图片流转为图片的问题 如何用泛型实现这样的二维数组 confirm 在ie7中失效了吗??? TreeView问题 关于ASP.NET的时间问题 可以用虚拟目录建文件夹? 为什么我向DataGrid中添加的CheckBox列在提交后就没有了? c#中日期时间的方法、函数 asp.net 求两张图片的相似度 超链接打开文件乱码
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
<error statusCode="404" redirect="404.htm" />
</customErrors>
<error statusCode="404" redirect="~/FileNotFound.htm" />
</customErrors>protected void Application_Error(Object sender, EventArgs e)
{
string strStatus = Context.Response.StatusCode.ToString() ;
Exception objErr = Server.GetLastError().GetBaseException();
string error = "发生异常页: " + Request.Url.ToString() + "<br>";
error += "异常信息: " + objErr.Message + "<br>";
Server.ClearError();
Application["error"] = error;
Response.Redirect("ErrorPage.aspx");
}
当程序判断这个id不存在http://www.abc.com/404.htm当程序判断这个id不存在。就报404错误,并跳出404自定义页面,这样能实现吗?这样算不算是302跳转呢?
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
Web.Config