Besides simply redirecting from HTTP to HTTPS, the RequireHttps attribute also changes my URL's question mark ?
to %3F
. Unsurprisingly, that breaks things.
Why? How do I fix it?
scenario:
I try to navigate to
http://www.example.com/message/compose
But let's say I don't have permission to view that page.
<HandleError()> _ Public Class MessageController Inherits System.Web.Mvc.Controller
End ClassFunction Compose() As ActionResult ... If ... Then Throw New Exception(Net.HttpStatusCode.Unauthorized.ToString) End If ... Return View() End Function ...
The action throws an exception.
The exception is handled by my Error.aspx page
<%@ Page Language="VB" Inherits="System.Web.Mvc.ViewPage(Of System.Web.Mvc.HandleErrorInfo)" %> <script runat="server"> Sub Page_Load(ByVal Sender As System.Object, ByVal e As System.EventArgs) If Model.Exception.Message = Net.HttpStatusCode.Unauthorized.ToString Then response.redirect("/signin?ReturnUrl=" + Url.Encode(request.Path)) End If ... End Sub </script> ...
I'm redirected to my Sign In page at
http://www.example.com/signin?ReturnUrl=%2fmessage%2fcompose
But I'm using HTTP and not HTTPS. My action requires HTTPS. (That RemoteRequireHttps inherits from RequireHttps and overrides its OnAuthorization method to simply disregard localhost.)
<HandleError()> _ Public Class AccountController Inherits System.Web.Mvc.Controller
End Class<RemoteRequireHttps()> _ Function SignIn() As ActionResult ... End Function ...
I'm redirected to
https://www.example.com/signin%3FReturnUrl=%2fmessage%2fcompose
I see this error in my browser:
Bad Request
It seems that RequireHttps changes my question mark ?
to %3F
.