Razor MVC3, the usage of RequireHttpsAttribute results in a http 310 error.

Unanswered Razor MVC3, the usage of RequireHttpsAttribute results in a http 310 error.

  • Thursday, April 12, 2012 8:49 PM
     
      Has Code

    Hey,

    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



    • Edited by Feanaro Thursday, April 12, 2012 8:53 PM
    • Moved by Bob_BaoMVP Monday, April 16, 2012 4:50 AM (From:Visual Basic General)
    •  

All Replies

  • Monday, April 16, 2012 4:49 AM
     
     

    Hi Feanaro,

    Thanks for your post. However, I am sorry that here is not the correct forum for you to deal with your issue. I would suggest you post your case at: http://forums.asp.net/ .

    Thanks.


    Shanks Zen
    MSDN Community Support | Feedback to us