locked
HttpErros not working IIS Server RRS feed

  • Question

  • User-1078128378 posted

    Hi All,

    I am using IIS 10 and vs 2015

    I have sample test application it contains sample default.aspx page and Error404.aspx page.

    i want to perform if an user requested any 404 resource then i want to redirect to Error404.aspx page.

    so that i created sample test application which is working properly on FIleSystem project (http://localhost:16573/)

    and i created same application in IIS then it is not working

    when i requested any non existing page in my application then it is showing console error instead of redirecting to Error404.aspx page

    I wrote below code in web.config file

    <system.webServer>
        <httpErrors existingResponse="Replace" errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="Error404.aspx" responseMode="ExecuteURL" />
        </httpErrors>
        <!--<modules runAllManagedModulesForAllRequests="true"/>-->
      </system.webServer>

    could any one please tell me why it is not working

    FYI: I enabled HTTP Erros option in IIS Features from control panel.

    Thank you,

    Monday, April 23, 2018 6:47 AM

All replies

  • User475983607 posted

    A blank screen usually indicates IIS is not configured correctly.  Does default.aspx open in the browser?

    Monday, April 23, 2018 2:52 PM
  • User753101303 posted

    Also try perhaps path="/Error404.aspx" or path="~/Error404.aspx" ? (I Wonder if it could happen because the error page itself is not found for now ?)

    Monday, April 23, 2018 5:39 PM
  • User-1078128378 posted

    Hi Patrice,

    Thanks for the reply 

    I tried both path="/Error404.aspx" or path="~/Error404.aspx"

    if i used path="/Error404.aspx" and I opened non existing page in browser then it returns below error

    Server Error in '/' Application.


    The resource cannot be found.

    Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

    Requested URL: /Error404.aspx


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2633.0

    if i used path="~/Error404.aspx" and opened non existing page in browser then it returns below error

    it shows empty page , in console window it displays below message

    Failed to load resource: the server responded with a status of 404 (Not Found)

    Tuesday, April 24, 2018 6:13 AM
  • User283571144 posted

    Hi Murali,

    murali krishna14

    I wrote below code in web.config file

    <system.webServer>
        <httpErrors existingResponse="Replace" errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="Error404.aspx" responseMode="ExecuteURL" />
        </httpErrors>
        <!--<modules runAllManagedModulesForAllRequests="true"/>-->
      </system.webServer>

    could any one please tell me why it is not working

    According to your web config codes, I have created a demo on my side, it works well.

    I used  web config codes. as below.

      <system.webServer>
        <httpErrors existingResponse="Replace" errorMode="Custom">
          <remove statusCode="404" subStatusCode="-1" />
          <error statusCode="404" prefixLanguageFilePath="" path="/Error404.aspx"  responseMode="ExecuteURL"  />
        </httpErrors>
      </system.webServer>

    My project view:

    Result:

    According to the error message, it means the server could'd find the Error404 url.

    I guess there is route on your web site's.So it couldn't locate the error404 page.

    I suggest you could create a new empty website and test again.

    Best Regards,

    Brando

    Thursday, April 26, 2018 5:23 AM
  • User-1078128378 posted

    Hi Brando,

    Thanks for the reply

    I created sample Test application it does not have any route configuration.

    it is working properly in FIle System.(http://localhost:53422/)

    but when i hosted same application in Local IIS then it is not redirecting to Error404.aspx Page if i requested any unExisted file

    Sunday, April 29, 2018 10:17 AM