Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i specify a custom error page without setting defaultPath on httpErrors in the web.config?

I'm currently working on deploying a asp.net website to a shared hosted environment, and this works as expected (404 pages render)

<httpErrors errorMode="Custom">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/file-not-found.htm" responseMode="ExecuteURL" />
</httpErrors>

but this doesn't (500 internal server error)

<httpErrors errorMode="Custom" defaultPath="error.htm" defaultResponseMode="ExecuteURL">
    <remove statusCode="404" subStatusCode="-1" />
    <error statusCode="404" prefixLanguageFilePath="" path="/file-not-found.htm" responseMode="ExecuteURL" />
</httpErrors>

I asked to take a look at the applicationHost.config and it has:

<httpErrors errorMode="Custom" defaultPath="C:\inetpub\custerr\en-US\SSLRedirect.htm" lockAttributes="allowAbsolutePathsWhenDelegated,defaultPath">

So I'm assuming that the defaultPath as a locked attribute is the thing that's causing issues.

Because this is being deployed to a shared environment, the hosting company is not willing to modify the applicationHost.config to remove the lock on defaultPath - so is there any way to specify a default error page without unlocking the defaultPath attribute?

like image 867
Henry C Avatar asked Nov 29 '25 22:11

Henry C


1 Answers

In global.asax you could just implement Application_Error() and redirect to wherever you want?

like image 143
Eric Avatar answered Dec 01 '25 13:12

Eric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!