52781

Where is the source for RequireHttpsAttribute?

Question:

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?

Answer1:

I just downloaded the source for <a href="http://aspnet.codeplex.com/releases/view/58781" rel="nofollow">ASP.NET MVC 3 RTM</a> 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); } } }

Answer2:

Do you mean RequireSslAttribute? <a href="http://aspnet.codeplex.com/SourceControl/changeset/view/63930#391756" rel="nofollow">http://aspnet.codeplex.com/SourceControl/changeset/view/63930#391756</a>

Recommend

  • TYPE_CLASS_NUMBER input type on android scrolls ScrollView to it's right end. Why?
  • Variable before or after value in IF statement
  • unexpected unicode values in dataframe?
  • CSS-only photo grid with horizontal fill
  • What are the Disadvantages of Early Binding?
  • How do I get Timeline data from Glimpse for reporting?
  • Ninject and Custom Controller Factory
  • Inheritance impossible in Windows Runtime Component?
  • add sql server data connection in visual studio
  • Generic lambda xcode 8.3.3
  • Why do the PHP preg_* functions require regexp delimiters? [closed]
  • Set C# Property that has no Setter
  • Memory allocation of base class and derived class constructor
  • EF Code First Foreign Key's
  • Windows Azure VM availability/Failover steps
  • java 1.6 32-bit min and max heap memory issue
  • Foreign key pointing to Compound Key
  • Testing a python script in a specific version
  • How to send basicAck to inbound adapter after publisher confirm from outbound adapter
  • Liferay: After changing Public Virtual Host settings, can't log in
  • C++ design pattern: multiple ways to load file
  • Why String.ToString()? [duplicate]
  • Complex Object won't return when using 'include' syntax in WCF with Entity Version 6
  • Required Attribute does not work on foreign key dropdown list
  • Entity framework - Foreign key - data annotation
  • friend declaration in protected section
  • Java ClassLoader Confusion
  • SQL Server Integrated Security from an Azure Web Site
  • Is it one-to-one or Component ? Nhibernate Mapping
  • Installing PAR::Packer on Windows, dmake error 255
  • CSS Grid, position absolute an element in a css grid item: IMPOSSIBLE
  • Specifying virtual keyboard type for EditText in XML
  • Feature detection of foreignObject in SVG
  • javaw.exe and eclipse startup problems
  • How to format a variable of double type
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Binding checkboxes to object values in AngularJs