Require SSL but still keep asp.net custom errors
NickName:toddmo Ask DateTime:2017-03-02T06:16:07

Require SSL but still keep asp.net custom errors

I have asp.net custom errors and they are working great:

<customErrors mode="RemoteOnly" defaultRedirect="~/Error/Index/500">
  <error statusCode="403" redirect="~/Error/Index/403" />
  <error statusCode="404" redirect="~/Error/Index/404" />
  <error statusCode="500" redirect="~/Error/Index/500" />
  <error statusCode="502" redirect="~/Error/Index/502" />
  <error statusCode="503" redirect="~/Error/Index/503" />
  <error statusCode="504" redirect="~/Error/Index/504" />
</customErrors>

Also, the ssl certificate has been successfully installed and my site is accessible just fine from both http and https.

Issue came about when I got a requirement to require SSL. The http link to the site has already been distributed to 1000 users. So we need any traffic going to the http address to be gracefully redirected to the https home page.

Any solution I've tried to get the redirect working breaks the custom errors.

I have this test url that generates an error to test my custom error pages at ~/error/test. It shows my custom error page using the mvc layout.

No matter how I set it up, once I turn on Require SSL within the SSL Settings in IIS, if I turn on any http custom errors (so that the 403.4 redirect is enabled), it doesn't even try to show my custom 500 page. It shows the generic http 500 page.

I want 403.4 handled at http level with a redirect and 500 to be handled at the asp.net level with my custom error page. Which incidentally is not a page but a controller that uses the .net exception which is in a session variable.

How can I accomplish this?

Copyright Notice:Content Author:「toddmo」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/42543154/require-ssl-but-still-keep-asp-net-custom-errors

More about “Require SSL but still keep asp.net custom errors” related questions

Require SSL but still keep asp.net custom errors

I have asp.net custom errors and they are working great: &lt;customErrors mode="RemoteOnly" defaultRedirect="~/Error/Index/500"&gt; &lt;error statusCode="403" redirect="~/Error/Index/403"

Show Detail

require client certificates in IIS without requiring SSL

In IIS 7, I've created an https binding for a site, and I'd like to require client certificates for https and still keep my http endpoint. That is to say, I'd like to require client certificates ...

Show Detail

IIS 7 Disabling "Require SSL"

Deployed an ASP.NET application to our internal production server as a virtual directory under the default web site. I had been getting 403 errors when trying to connect to it. So I verified the ...

Show Detail

ASP.NET Custom errors for developer machines

Does this ever happen to you? You are sitting at your development machine and you are made aware of an unhandled exception in a deployed asp.net application. You visit the deployed web app. You ca...

Show Detail

ASP.NET Custom errors for developer machines

Does this ever happen to you? You are sitting at your development machine and you are made aware of an unhandled exception in a deployed asp.net application. You visit the deployed web app. You ca...

Show Detail

Error when setting require SSL=true Asp.net

I am working in an Asp.net application with forms authentication. On my web.config I had set the requiressl property=true. I have been working on development without any problem but when I deploy ...

Show Detail

How to keep asp.net development server still running?

How to keep asp.net development server still running? I'm developing a asp.net mvc project. After I uninstall Resharp. The server will be only launched at debugging. Is there any way to keep it ...

Show Detail

2-Way SSL (Mutual Authentication) in ASMX and ASP.Net

I'm researching on how integrate 2-way SSL in two IIS servers ASP.Net web site is hosted in one server. ASMX web services is hosted in another server. They both run under Dot Net 3.5 in Windows S...

Show Detail

ASP.NET Custom Errors vs. Compilation debug="false" and security

I keep reading that an ASP.NET based web site should have custom errors enabled in the web.config because exceptions will show a stack trace. I may have a faulty memory (currently don't have acces...

Show Detail

Can SSL and a key code alone be enough to keep a Web API secure?

I have an ASP.Net Web API (v2) that will require SSL for all calls made to it, no exceptions. There is no login for the system, instead I plan on providing a user with a secret key key code that will

Show Detail