开发者

Global_Asax Application_Error Fired instead of default IIS7 404 Page Not Found Page

开发者 https://www.devze.com 2023-01-27 15:30 出处:网络
I have a Web Application which has Global_Asax and a Custom Error Page. When user tries to enter to an invalid page which doesn\'t exist, Application_Error is fired in Global_asax and exception is log

I have a Web Application which has Global_Asax and a Custom Error Page. When user tries to enter to an invalid page which doesn't exist, Application_Error is fired in Global_asax and exception is logged which isn't really an exception (You can see the exception detai开发者_JAVA百科ls below). I don't want to handle this case in global_asax but rather in IIS. I've also tried to enter invalid paths ending with .asp and .html and they work fine(They don't end in global_asax but rather in default 404 page).

I need to know which setting I have to change from IIS7 Manager.

Any help would be appreciated.

Error - The file '/restricted/ff.aspx' does not exist.

System.Web.HttpException: The file 'test.aspx' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


You can try one of these:

  1. Edit the web.config file for custom errors:

    <customErrors mode="On">
        <error statusCode="404" redirect="404.aspx"/>
    </customErrors>
    
  2. Add a 404.aspx page and set the status code to 404:

    public partial class _04 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.StatusCode = 404;
        }
    }
    

If it doesn't help you try this as well (it might be reset by your masterpage):

protected override void Render(HtmlTextWriter writer)
{
    base.Render(writer);
    Response.StatusCode = 404;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消