简体   繁体   English

如何将我的MVC 3应用程序配置为在登录时使用HTTP,在其余页面上使用HTTPS?

[英]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.

相关问题 Facebook登录建议要求HTTPS - 如何在ASP.NET MVC中为Facebook登录配置HTTP重定向URL? - Facebook Login recommending to require HTTPS - How to Configure HTTP redirect URL for Facebook Login in ASP.NET MVC? 如何将HTTP处理程序用于选定路径,将MVC处理程序用于其他路径? - How do I use my HTTP handlers for selected paths and MVC handler for the rest? 登录后,我的应用保持重定向到登录页面(MVC 5) - My App keep redirect to login pages after login (MVC 5) 如果我的应用包含两个不同的登录页面,如何将用户重定向到适当的登录? - How do I redirect users to the appropriate login, if my app contains two different login pages? 如何在MVC asp.net中让控制器允许HTTP和https流量? - How can I have a controller allow http and https traffic in MVC asp.net? 如何使MySqlSessionStateProvider在.NET MVC应用程序中使用Cookie? - How can I make the MySqlSessionStateProvider use cookies in my .NET MVC app? 如何在我的ASP.NET MVC应用程序中使用jQuery选项卡进行导航? - How can I use jQuery tabs for navigation in my ASP.NET MVC app? 如何在MVC中配置子路由 - How can I configure sub routes in MVC 如何基于ASP.NET MVC中的控制器操作在页面javascript中设置变量? - How can I set a variable in my pages javascript based on my controller action in ASP.NET MVC? 我可以在自己的登录/注册页(MVC)中使用Azure AD B2C吗? - Can I use Azure AD B2C in my own login/registration page(MVC)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM