How to disable [RequireHttps] for all methods during debugging?

I have a MVC2 website with a lot [RequireHttps].

But when I debug it, I have to comment on many of them in different places (controllers). And when the code is ready, I have to delete all comments.

Therefore, it takes time, and sometimes I forgot to uncomment [RequireHttps]:)

My question is, what methods best solve this problem?

Thank!

+5
source share
6 answers

I would use # if (C # Reference) and have a debug and release configuration:

Then you:

#if RELEASE
    [RequireHttps]
#endif
void methodHere()
{
...
}
+3
source

#if , , op , RequireHttps :

#if DEBUG
public class ReleaseRequireHttpsAttribute : Attribute
{
    // no-op
}
#elif
public class ReleaseRequireHttpsAttribute : RequireHttpsAttribute
{
    // does the same thing as RequireHttpsAttribute
}
#endif

[RequireHttps] [ReleaseRequireHttps] .

+8

" " , ​​ , . ( ) , , , .

- SSL, IIS Express. - Visual Studio 2010, IIS, HTTP. :

http://learn.iis.net/page.aspx/901/iis-express-faq/

IIS Express, https IIS Express .

+4

DRY :

public class CustomRequireHttpsAttribute : RequireHttpsAttribute
{
    /* override appropriate method with preprocessor directives */
}

[CustomRequireHttps]
public ActionResult Foo(string foo) { /* ... */ }

[CustomRequireHttps]
public ActionResult Bar(string bar) { /* ... */ }
+2

#if RELEASE ... #endif:

#if RELEASE
    [RequireHttps]
#endif
void YourMethod()
{
    ...
}
+1

, HTTPS-, Visual Studio:

/// <summary>
/// Requires HTTPS connection unless running under Visual Studio debugger.
/// </summary>
public class RemoteRequireHttpsAttribute : RequireHttpsAttribute
{
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
        if (filterContext != null 
            && filterContext.HttpContext != null 
            && filterContext.HttpContext.Request.IsLocal)
            return;

        base.OnAuthorization(filterContext);
    }
}
0