Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have some MVC2 website that has a lot of [RequireHttps].

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

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

My question is which is best practices to resolve this problem?

Thank you!

like image 812
Friend Avatar asked Jul 07 '12 18:07

Friend


2 Answers

If you don't want to type #if statements around every usage, you can make a new attribute that is a no-op in debug builds, and a simple subclass of RequireHttps in release builds:

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

Then simply find-and-replace every [RequireHttps] with [ReleaseRequireHttps] and use that for new methods.

like image 104
kevingessner Avatar answered Nov 20 '22 00:11

kevingessner


Since you asked about "best practices" for solving this problem, the best practice in this case is to leave the attributes in place and debug the exact same code that you deploy. Any of the other answers (all of which will work) will mean that you are debugging code, then changing your code before you deploy, which is never a good idea.

In this case, it's easy enough to debug web projects over SSL if you use IIS Express. This is a drop-in replacement for the Visual Studio 2010 web server, but with most of the features of IIS, including secure HTTP support. More information can be found here:

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

Once installed, you can switch your projects to use IIS Express, set up an https binding in the IIS Express configuration, and step through as normal.

like image 4
Michael Edenfield Avatar answered Nov 20 '22 02:11

Michael Edenfield