Redirect loop during http:// to https:// redirect

纵然是瞬间 提交于 2019-12-08 09:37:56

问题


I am trying to force a page to be run under SSL, so I have implemented the following on page_load:

if (!Request.IsLocal && !Request.IsSecureConnection)
        {
            Response.Redirect(Helper.GetInstance().SSLBaseURL() + ScriptName());
        }

For some reason this is ending up in a loop. Earlier today, I checked Request.Uri.Scheme, and it was resolving as "http", though I was clearly connected to https://www.domain.com/pagename.aspx.

Any reason you can think of why this page isn't correctly detecting that we're running under https?


回答1:


I would handle this on the webserver side. If you're running IIS, it's not as simple, but you could enable the force SSL option and implement a custom error page for your 403;4 (I think that's the SSL required error) that redirects to https.



来源:https://stackoverflow.com/questions/939592/redirect-loop-during-http-to-https-redirect

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