I have combined some of my web applications into one of the main ASP.NET MVC projects; assigning some of them to separate areas so that they can be accessed through subdomains.
Using this (very useful) resource ( https://dusted.codes/demystifying-aspnet-mvc-5-error-pages-and-error-logging ), I set customErrors and httpErrors to Web.config so that user pages are displayed mistakes. It works well.
I use different layouts / styles for the region / subdomain, so I wonder: How can I get Area to display my own set of error pages?
In the current configuration, all subdomains will display the main set of user errors that are added to the customErrors and httpErrors (403.html, 404.html, etc.); but I would prefer to set up error pages for some subdomains. (If, for example, one of the areas is handled exclusively by a separate domain, for example, it would be inappropriate to serve regular error pages.)
Update: Here is a script, with code, on request. Thanks to Ben Foster, who suggested good recommendations here: http://benfoster.io/blog/aspnet-mvc-custom-error-pages 2 . I put the code for customErrors, but not the corresponding httpErrors ... left it for brevity.
<system.web> <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/500.aspx"> <error statusCode="404" redirect="~/404.aspx" /> <error statusCode="500" redirect="~/500.aspx" /> </customErrors> </system.web> <location path="MyArea1"> <system.web> <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Areas/MyArea1/500.aspx"> <error statusCode="404" redirect="~/Areas/MyArea1/404.aspx" /> <error statusCode="500" redirect="~/Areas/MyArea1/500.aspx" /> </customErrors> </system.web> </location> <location path="MyArea2"> <system.web> <customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Areas/MyArea2/500.aspx"> <error statusCode="404" redirect="~/Areas/MyArea2/404.aspx" /> <error statusCode="500" redirect="~/Areas/MyArea2/500.aspx" /> </customErrors> </system.web> </location>
The above code works well:
- If I go to "example.com/does/not/exist", I get the expected error page
~/404.aspx . - If I go to "example.com/MyArea1/does/not/exist", I will get a user error page
~/Areas/MyArea1/404.aspx .
Task:
Now I want the area (MyArea2) to be served by a completely separate domain (e.g. exampleOnMyOtherDomain.com) using HostDomainConstraint (as recommended by @TetsuyaYamamoto, in the comment below). A link will now be available that would be accessible via "example.com/MyArea2/validlink": "exampleOnMyOtherDomain.com/validlink".
Now, if I try "exampleOnMyOtherDomain.com/does/not/exist", I will serve 404 top level ( ~/404.aspx ). This is probably because "MyArea2" is no longer in the path, so the location using the "MyArea2" path will not be found.
How can I get Area (MyArea2) to serve my own error pages?
asp.net-mvc web-config custom-errors
cyrotello
source share