I’m trying to build a web application that uses an SSL connection. So I did some research and found out that I could use the RequireHttpsAttribute class to achieve what I needed. Thing is that when I use it, the execution of the application results in an 310 error(too many redirections). I even built a custom class to handle the switch from http to https. But that too results in an error.
My Class to handle te protocol switch:
Public Class RequireSSLAttribute
Inherits ActionFilterAttribute
Public Property IsRequired() As Boolean
Public Overrides Sub OnActionExecuting(filterContext As ActionExecutingContext)
If Me.IsRequired AndAlso filterContext.HttpContext.Request.Url.Scheme <> "https" Then
filterContext.HttpContext.Response.Redirect(filterContext.HttpContext.Request.Url.OriginalString.Replace("http:", "https:").Remove(filterContext.HttpContext.Request.Url.OriginalString.LastIndexOf(":") + 1), True)
filterContext.Result = New HttpUnauthorizedResult
End If
End Sub
Public Sub New()
IsRequired = True
End Sub
End Class
I don’t know who your host is, but I just ran into a similar problem on AppHarbor and discovered this in their knowledge base:
They have also provided an example solution on Github here, which I will copy below for convenience:
I’m not sure if this will solve your problem; but perhaps even if you aren’t using AppHarbor the root cause may be the same for you, in which case the above seems worth a shot.