Thursday, April 12, 2012 8:49 PM
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. Could someone please help me a hand?
My class to handle the 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
Monday, April 16, 2012 4:49 AM