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!
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With