SSL and relative URLs in site links and redirections

人走茶凉 提交于 2019-12-13 07:20:38

问题


I have been working on a website in beta phase for some time now, and am finally about to launch it. There are several links, anchor tags, with relative URLs throughout the site that link to the admin and cart sections of the website, and now they have to be SSL secured.

Also, same question for relative URLs in Response.Redirect("~/../..");

When a user is browsing over http, is there anyway to redirect them to a page with https connection using a relative URL? It seems like poor practice to code absolute URLs for links and redirections for the purpose of SSL. If the domain name changes, I have to rewrite them all. Plus, if I want them to work on my localhost, I would have to change them every time I upload to server. There must be some solution.


回答1:


Switching Between HTTP and HTTPS Automatically is a very good code to use for the implementation of switching logic fast and easy - and not change your existing code.

Similar: Preparing my ASP.NET / MVC site to use SSL?




回答2:


These helper methods by Rick Strahl will help you

http://www.west-wind.com/weblog/posts/2007/Sep/18/ResolveUrl-without-Page

Pay special attention to ResolveServerUrl.




回答3:


Depending on what version of IIS you are running, you could always offload this functionality to the webserver. Check out the URL Rewrite module here.



来源:https://stackoverflow.com/questions/12222168/ssl-and-relative-urls-in-site-links-and-redirections

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