1

ASP.NET MVC includes the attribute RequireHttpsAttribute to force SSL connections, however in looking at codeplex, the source file for it is nowhere to be found. Am I not looking in the correct place?

tereško
  • 58,060
  • 25
  • 98
  • 150
dreadwail
  • 15,098
  • 21
  • 65
  • 96

2 Answers2

8

I just downloaded the source for ASP.NET MVC 3 RTM and found it in the System.Web.Mvc project:

namespace System.Web.Mvc {
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Web.Mvc.Resources;

    [SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", Justification = "Unsealed because type contains virtual extensibility points.")]
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class RequireHttpsAttribute : FilterAttribute, IAuthorizationFilter {

        public virtual void OnAuthorization(AuthorizationContext filterContext) {
            if (filterContext == null) {
                throw new ArgumentNullException("filterContext");
            }

            if (!filterContext.HttpContext.Request.IsSecureConnection) {
                HandleNonHttpsRequest(filterContext);
            }
        }

        protected virtual void HandleNonHttpsRequest(AuthorizationContext filterContext) {
            // only redirect for GET requests, otherwise the browser might not propagate the verb and request
            // body correctly.

            if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) {
                throw new InvalidOperationException(MvcResources.RequireHttpsAttribute_MustUseSsl);
            }

            // redirect to HTTPS version of page
            string url = "https://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
            filterContext.Result = new RedirectResult(url);
        }

    }
}
Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
0

Do you mean RequireSslAttribute? http://aspnet.codeplex.com/SourceControl/changeset/view/63930#391756

Luke
  • 8,235
  • 3
  • 22
  • 36
  • No, I mean RequireHttpsAttribute. http://msdn.microsoft.com/en-us/library/system.web.mvc.requirehttpsattribute.aspx Unless they have renamed it. Are you implying that it has been renamed? – dreadwail Mar 03 '11 at 00:33