Asp.net从HTTPS重定向到http [英] Asp.net Redirecting from Https to Http

查看:478
本文介绍了Asp.net从HTTPS重定向到http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从安全的重定向(HTTPS)到HTTP时,用户登录。它重定向罚款,但由于某种原因其保持HTTPS。

I am trying to redirect from secure (https) to http when user login. It redirects fine but for some reason its keeping the https.

 Response.Redirect(RedirectPath)

RedirectPath 包含完整的URL包括http。

RedirectPath contains fully qualified URL including http.

例如 RedirectPath =htt​​p://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;
        }
    }
}

您同样可以从https访问http由计划设置为 UriSchemeHttp 如果 IsSecureConnection 是真实的。

You can similarly go from https to http by setting the Scheme to UriSchemeHttp if IsSecureConnection is true.

这篇关于Asp.net从HTTPS重定向到http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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