DSh*_*per 38 .net c# asp.net visual-studio
在我的ASP.NET Web应用程序中,我在web.config文件中定义了自定义错误页面,如下所示:
<customErrors mode="On" defaultRedirect="~/default.html">
<error statusCode="404" redirect="~/PageNotFound.html" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
在404错误的情况下,我的站点重定向到default.html
页面,但它将"aspxerrorpath"作为查询字符串参数传递给自定义错误页面,如下所示:
http://www.example.com/default.html?aspxerrorpath=/somepathcausederror/badpage.aspx
Run Code Online (Sandbox Code Playgroud)
我不希望这种行为.我希望重定向网址只需阅读:
http://www.example.com/default.html
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?
Mat*_* J. 70
如果在指定路径时提供自己的查询字符串变量,那么.NET将不会添加"aspxerrorpath".谁知道?
例如:
<customErrors mode="On" defaultRedirect="errorpage.aspx?error=1" >
Run Code Online (Sandbox Code Playgroud)
这样就可以了.我不得不将这个添加到一堆应用程序,因为默认情况下,URLScan for IIS拒绝任何包含"aspxerrorpath"的内容.
Gar*_*ams 11
在global.asax中,捕获404错误并重定向到找不到文件的页面.我不需要aspxerrorpath,它对我有用.
void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
{
Response.Redirect("~/filenotfound.aspx");
}
else
{
// your global error handling here!
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以将自己的url参数发送到错误页面
<customErrors mode="On" defaultRedirect="~/default.html?404">
<error statusCode="404" redirect="~/PageNotFound.html?404" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
49503 次 |
最近记录: |