始终需要Https到特定路线

Pir*_*ada 1 routing asp.net-mvc-3

我有SSL的MVC3应用程序.我想要特定的页面URL应该总是添加Https.有人能告诉我怎么做.以下是全局文件中的路径.

 routes.MapRoute("root22",
                "paybill",
                new { controller = "Home", action = "PayBill" });
Run Code Online (Sandbox Code Playgroud)

还有一件事,如果我的URL前面有https而不是页面中的所有路径也使用https或不需要?

Bra*_*don 5

您不需要弄乱路由来完成此任务.只需[RequireHttps]在控制器/操作上使用该属性即可.

[RequireHttps]
public ViewResult YourAction()
Run Code Online (Sandbox Code Playgroud)

如果可以,它将重定向到https.您的外发链接不必使用https,但在加载javascript,css,图像等时,否则用户可能会收到混合内容安全警告.