I have an MVC app that is working fine, but I now want to add in an SSL site to the app.
我有一个工作正常的MVC应用程序,但我现在想要在应用程序中添加一个SSL站点。
This is a separate site in IIS, with the SSL certificate, but for re-use, I'm just pointing the SSL site to the same directory as the regular site.
这是IIS中的一个单独的站点,带有SSL证书,但是为了重用,我只是将SSL站点指向与常规站点相同的目录。
What I'd like to do now, is direct the user to a certain controller (payment) if they come in on the secure url. Otherwise, they can continue on as they were.
我现在要做的是,如果他们进入安全网址,则将用户指向某个控制器(付款)。否则,他们可以继续保持现状。
What is the best way to do this?
做这个的最好方式是什么?
Routing? Filters? Custom BaseController?
路由?过滤器?自定义BaseController?
How can I ensure that no matter what route they try, if their Request.Url.Host is my secure url, then they'll get redirected. In the future if I add new controllers and actions, I don't want to have to put this in every controller.
我怎样才能确保无论他们尝试什么路线,如果他们的Request.Url.Host是我的安全网址,那么他们将被重定向。将来,如果我添加新的控制器和操作,我不想将其放在每个控制器中。
Is there a way, application wide, that I can tell all controllers to redirect if a certain url is found?
是否存在应用程序范围的方法,如果找到某个URL,我可以告诉所有控制器重定向?
2 个解决方案
#1
2
Decorate your method with:
用以下方法装饰你的方法:
[RequireSsl(Redirect = true)]
#2
0
[RequireHttps]
is now part of ASP.NET MVC 2
[RequireHttps]现在是ASP.NET MVC 2的一部分
#1
2
Decorate your method with:
用以下方法装饰你的方法:
[RequireSsl(Redirect = true)]
#2
0
[RequireHttps]
is now part of ASP.NET MVC 2
[RequireHttps]现在是ASP.NET MVC 2的一部分