asp.net - Why can't I get my site to recognize a default error page for status code 404 in a WebMatrix WebPages environment? -
i have seen in multiple places
[and previous question here] how can make custom error page in asp.net web-pages webmatrix?
how setup web.config file force custom error pages given status codes (i think ones care "500" , "404").
i using <system.web>
element in web.config xml.
<system.web> <compilation debug="true" targetframework="4.0"><assemblies><add assembly="system.configuration, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a" /></assemblies></compilation> <customerrors mode="on"> <error statuscode="500" redirect="~/error.cshtml" /> <error statuscode="404" redirect="~/error404.cshtml" /> </customerrors> </system.web>
the custom error page status code, "500" serves fine on normal server-side errors, reason, no matter do, can't seem custom error page status code "404" show if, say, broken link clicked on page. instead, shows normal "404, resource not found" default page.
i have tried change order of <error>
tags (not that should help, can see, out of reasonable things try, lol).
am misunderstanding how whole thing works or getting configuration/syntax wrong in way?
--------------------------------update----------------------------------------
okay, apparently, custom 404 page works if normal link broken, however, have .cs
file html generating methods in it.
on single secondary page, it's entire contents:
@html.raw(contentgenerator.generate("citycouncil"))
the values display on page come database, encoded added string, , written page. if c# string contains broken link, default error page not show up. why should make difference? guess is, it's timing issue, , time c# writes html page, web.config file can no longer influence link or something.
is there way still achieve default error page these links?
the customerrors
entry in web.config under system.web
works urls file extensions have established. work extension-less urls, need override iis adding entry system.webserver
node in web.config:
<system.webserver> <httperrors existingresponse="replace" errormode="custom"> <remove statuscode="404" substatuscode="-1" /> <error statuscode="404" prefixlanguagefilepath="" path="/error404.cshtml" responsemode="executeurl" /> </httperrors> </system.webserver>
having done this, need move other custom error handling system.webserver
section , remove customerrors
entry under system.web
.
Comments
Post a Comment