在.NET网站上,如果有人试图通过https访问它们,将html页面redirect到http的最佳方式是什么?
我正在使用Global.asaxredirectaspx页面,但没有selecthtml页面…
谢谢
IIS可以被configuration为执行redirect本身,如果可能的话这将是最好的方法。
另一种方法是继续在Global.asax中使用redirect,但将IISconfiguration为发送更多的请求,包括对.net运行时的.html文件的请求。 你应该可以通过网站在网站上做到这一点。 然后,您可以创build一个HttpHandler,该代码将执行redirect。 这可以通过在web.config中添加一行来configuration
<httpHandlers> <add verb="*" path="*.html" type="You.Namespace.Handlers.RedirectHandler"/> <add verb="*" path="*.htm" type="You.Namespace.Handlers.RedirectHandler"/> ... </httpHandlers>
如果所有这个IIS站点( https://example.com )都是redirect,那么只能使用这种方法。
如果您通过.net运行时提供真实的.html页面,则会产生性能成本。
希望有所帮助。
尝试使用JavaScript
<head> <script type="text/javascript"> function LeaveHTTPS() { if(window.location.toString().search("https")>=0){ var newURL=window.location.replace("https","http"); window.location=newURL;} } windows.onload= function() {LeaveHTTPS()} </script> </head>