[英]How can I configure my MVC 3 app to use HTTP on login and HTTPS on the rest of the pages?
How can I configure my ASP.NET MVC 3 application to use HTTP on login and HTTPS on the rest of the pages? 如何将ASP.NET MVC 3应用程序配置为在登录时使用HTTP,在其余页面上使用HTTPS?
Now I configured the app to use HTTPS on every page including Login. 现在,我将应用程序配置为在包括“登录”在内的每个页面上使用HTTPS。
Does anyone have any suggestions? 有没有人有什么建议?
Thanks a lot. 非常感谢。
Jeff 杰夫
You can use the built-in RequireHttpsAttribute
see the documentation reference 您可以使用内置的
RequireHttpsAttribute
参见文档参考
You can set this on your controller class like this: 您可以在控制器类上进行如下设置:
[RequireHttps]
public Controller HomeController() { }
All actions of this controller will use Https. 该控制器的所有操作将使用Https。
Or directly on a controller action 或直接在控制器上执行操作
[RequireHttps]
public ActionResult Index() { }
You may also register this for the entire app on your global.asax 您也可以在global.asax上为整个应用程序注册
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new RequireHttpsAttribute());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.