Web Farm Framework and MVC 3: How to require Https on an Action Method?

拈花ヽ惹草 提交于 2020-01-15 06:55:24

问题


I know you can do this:

#if !DEBUG
    [RequireHttps] //apply to this action only
#endif

What if you are using Web Farm Framework where "the Controller" server receives an outside SSL 443 request, decrypts it, then forwards it to the Primary / Secondary servers using http 80 (without ssl?)

In this environment, I tried the [RequireHttps] attribute but it responded with "The page isn't redirecting properly" in Firefox. Firefox has detected that the server is redirecting the request for this address in a way that will never complete. It's recognizing it's not SSL, but because it strips off SSL, MVC won't ever see SSL attributes.

How would you rewrite certain action methods to use https in MVC 3 in a web farm? How can you do this with [RequireHttps] or do you have to cherry pick every URL in your website that requires ssl and "URL Rewrite" it?

EDIT:

I changed the controller to identify port 443 traffic and forward it to https on the web farm. I thought I could get away with only loading the SSL certs on the controller, but they need loaded on the Primary and Secondary as well (or only.)


回答1:


In your action method you can check for a secure connection:

if(Request.IsSecureConnection())
{
   // Secure connection logic here
}


来源:https://stackoverflow.com/questions/7656463/web-farm-framework-and-mvc-3-how-to-require-https-on-an-action-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!