加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

Asp.net从Https重定向到Http

发布时间:2020-12-15 22:36:46 所属栏目:asp.Net 来源:网络整理
导读:我试图在用户登录时从安全(https)重定向到http.它重定向很好但由于某种原因它保持https. Response.Redirect(RedirectPath) RedirectPath包含完全限定的URL,包括http. 例如RedirectPath =“http://www.mydomain.com” 但它重定向到https://www.mydomain.com
我试图在用户登录时从安全(https)重定向到http.它重定向很好但由于某种原因它保持https.
Response.Redirect(RedirectPath)

RedirectPath包含完全限定的URL,包括http.

例如RedirectPath =“http://www.mydomain.com”

但它重定向到https://www.mydomain.com

解决方法

我在Page_Load上运行以下重定向:
protected void Page_Load(object sender,EventArgs e)
{
    if (!IsPostBack)
    {
        if (!Request.IsLocal && !Request.IsSecureConnection)
        {
            var ub = new UriBuilder(Request.Url);
            ub.Scheme = Uri.UriSchemeHttps;
            ub.Port = -1; // use default port for scheme
            Response.Redirect(ub.Uri.ToString(),true);
            return;
        }
    }
}

如果IsSecureConnection为true,则可以通过将Scheme设置为UriSchemeHttp来类似地从https转到http.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读