ASP.NET MVC RequireHttps in Production Only

前端 未结 15 1859
花落未央
花落未央 2020-11-28 18:23

I want to use the RequireHttpsAttribute to prevent unsecured HTTP requests from being sent to an action method.

C#

[RequireHttps] //apply to all acti         


        
相关标签:
15条回答
  • 2020-11-28 19:07

    For MVC 3 I added my own FilterProvider (based on code found here: Global and Conditional Filters that, among other things (displaying Debug info for local users etc.) will decorate all actions with RequireHttpsAttribute when HttpContext.Request.IsLocal == false.

    0 讨论(0)
  • 2020-11-28 19:13

    As Joel mentioned you can alter the compilation by using the #if !DEBUG directive.

    I just found out that you can alter the value of the DEBUG symbol in the web.config file compilation element. Hope that helps.

    0 讨论(0)
  • 2020-11-28 19:17

    Deriving from RequireHttps is a good approach.

    To side step the issue entirely, you can use IIS on your local machine with a self-signed certificate too. IIS is faster than the built-in webserver, and you have the advantage that your development environment is more like production.

    Scott Hanselman has a great resource on a few ways to implement local HTTPS with VS2010 and IIS Express.

    0 讨论(0)
提交回复
热议问题