C#MVC网站要http强制跳转https,可使用以下方法:
- 在项目Global.asax文件 Application_Start()中添加过滤
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); GlobalFilters.Filters.Add(new RequireHttpsAttribute());//跳转HTTPS }
- 在项目webconfig文件中添加配置节点
<system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer>