Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This won't help if you run Release builds on your development workstation, but conditional compilation could do the job...</p> <pre><code>#if !DEBUG [RequireHttps] //apply to all actions in controller #endif public class SomeController { //... or ... #if !DEBUG [RequireHttps] //apply to this action only #endif public ActionResult SomeAction() { } } </code></pre> <h2>Update</h2> <p>In Visual Basic, attributes are technically part of the same line as the definition they apply to. You can't put conditional compilation statements inside a line, so you're forced to write the function declaration twice - once with the attribute, and once without. It does work, though, if you don't mind the ugliness.</p> <pre><code>#If Not Debug Then &lt;RequireHttps()&gt; _ Function SomeAction() As ActionResult #Else Function SomeAction() As ActionResult #End If ... End Function </code></pre> <h2>Update 2</h2> <p>Several people have mentioned deriving from <code>RequireHttpsAttribute</code> without providing an example, so here's one for you. I think that this approach would be much cleaner than the conditional compilation approach, and it would be my preference in your position.</p> <p>DISCLAIMER: I haven't tested this code, even a little bit, and my VB is fairly rusty. All I know is that it compiles. I wrote it based on the suggestions of spot, queen3, and Lance Fisher. If it doesn't work, it should at least convey the general idea, and give you starting point.</p> <pre><code>Public Class RemoteRequireHttpsAttribute Inherits System.Web.Mvc.RequireHttpsAttribute Public Overrides Sub OnAuthorization(ByVal filterContext As _ System.Web.Mvc.AuthorizationContext) If IsNothing(filterContext) Then Throw New ArgumentNullException("filterContext") End If If Not IsNothing(filterContext.HttpContext) AndAlso _ filterContext.HttpContext.Request.IsLocal Then Return End If MyBase.OnAuthorization(filterContext) End Sub End Class </code></pre> <p>Basically, the new attribute just quits out instead of running the default SSL authorization code, if the current request is local (that is, you're accessing the site through localhost). You can use it like this:</p> <pre><code>&lt;RemoteRequireHttps()&gt; _ Public Class SomeController &lt;RemoteRequireHttps()&gt; _ Public Function SomeAction() As ActionResult ... End Function End Class </code></pre> <p>Much cleaner! Provided my un-tested code actually works.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload