1

I tried to set up custom error handling in ASP .Net MVC Application. In Web.config I have this :

  <system.web>
    <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/page500.aspx">
      <error statusCode="404" redirect="~/Error/page404.aspx"/>
      <error statusCode="500" redirect="~/Error/page500.aspx"/>
    </customErrors>

and

<system.webServer>
  <handlers>
    <add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
  </handlers>
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <clear/>
    <error statusCode="404" responseMode="File" path="/Error/page404.html"/>
    <error statusCode="500" responseMode="File" path="/Error/page500.html"/>
  </httpErrors>
</system.webServer>

And When I try url's like :

http://localhost:49376/private/aaa

I can see my 404 custom error page

enter image description here

And when I try the url

http://localhost:49376/private/aaa<

I can also see my 500 custom error page

enter image description here

But when try urls like :

http://localhost:49376/private/aaa/foo/bar

I get the IIS default error page. And when I try

http://localhost:49376/private/aaa<script></script> 

I get the Runtime Default error page.

What am I missing ?

1
  • I'm not 100% sure, but I think that is an IIS protection thing, it will filter certain URLs that have potentially invalid or dangerous content in them. Commented Mar 10, 2016 at 17:20

1 Answer 1

1

I'm not sure, but it could be your elmah config. Read more about it here, espesially in the comments section: http://www.troyhunt.com/2012/01/aspnet-session-hijacking-with-google.html?m=1

I think this is a known Elmah issue if you set up the config a little wrong

So long story short, try this in your config:

<location path="elmah.axd">
  <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/page500.aspx">
  <error statusCode="404" redirect="~/Error/page404.aspx"/>
  <error statusCode="500" redirect="~/Error/page500.aspx"/>
</customErrors>
  <system.web>
    <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" 
        type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
    <authorization>
      <allow roles="Admin" />
      <deny users="*" />
    </authorization>
  </system.web>
  <system.webServer>
    <handlers>
      <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD"
        type="Elmah.ErrorLogPageFactory, Elmah"
        preCondition="integratedMode" />
    </handlers>
    <httpErrors errorMode="Custom" existingResponse="Replace">
    <clear/>
      <error statusCode="404" responseMode="File" path="/Error/page404.html"/>
      <error statusCode="500" responseMode="File" path="/Error/page500.html"/>
    </httpErrors>
  </system.webServer>
</location>
Sign up to request clarification or add additional context in comments.

1 Comment

But I still get the IIS Default error page for the url like 'localhost:49376/private/aaa/sss/sss'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.