根据http或https协议重定向用户 [英] Redirects the user based on http or https protocol

查看:113
本文介绍了根据http或https协议重定向用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我们的域名现在是http协议。一段时间后它将变为https。如果用户键入http:// domainName,我想要这样的代码,那么该页面上的所有相对链接都将自动重定向到http。如果用户键入https:// domainName,那么该页面上的所有相对链接都将自动重定向到https。

我如何使用asp.net做到这一点。



我尝试了什么:



我试图通过客户端javascript或jquery来做但不能弄清楚如何..

Hi,

Our domain is in now http protocol. It will be going to change to https after some time. I wanted to do such a code if user type http://domainName then all relative link on that page would be redirected to http automatically. IF user type https://domainName then all relative link on that page would be redirected to https automatically.
How I can do that using asp.net.

What I have tried:

I am trying to do it through client side javascript or jquery but not able to figure out how..

推荐答案

我相信你的方向是错误的。您无需更改代码,JavaScript和JQuery都无法在这方面为您提供帮助。这基本上是配置文件。



您需要配置IIS来处理https请求。如果您希望您的网站同时使用http和https协议,那么您将需要2个端口。



请参考以下文章一步一步学习。

什么是SSL以及如何在ASP.Net Web应用程序中实现 [ ^ ]

建立安全ASP.NET应用程序:身份验证,授权和安全通信 [ ^ ]

自动在HTTP和HTTPS之间切换:版本2 [ ^ ]

https://支持.microsoft.com / zh-CN / kb / 299875 [ ^ ]



希望,它有帮助:)
I believe you are in the wrong direction. You don't need to change your code, neither JavaScript nor JQuery can help you in this regard. This is basically configuration stuffs.

You need to configure your IIS to handle https requests. If you want your website to use both http and https protocols then you'll need 2 ports.

Please refer following articles to learn step by step process.
What is SSL and How to Implement in ASP.Net Web Application[^]
Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication[^]
Switching Between HTTP and HTTPS Automatically: Version 2[^]
https://support.microsoft.com/en-us/kb/299875[^]

Hope, it helps :)


你需要做的是重定向初始http请求而不是修改页面上的链接,因此如果有人请求http:// yoursite / url,则将其重定向到https:// yoursite / url。这样所有的链接都会默认为https(假设你已经正确地写了你的网站)。



Googleasp.net将http重定向到https和你会找到各种方法来实现这一目标。
What you need to do is redirect the initial http request rather than amending the links on the page, so if someone requests http://yoursite/url you redirect them to https://yoursite/url. That way all the links\images will be https by default (assuming you have written your site correctly).

Google "asp.net redirect http to https" and you'll find various ways of achieving this.


这篇关于根据http或https协议重定向用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆