【问题标题】:how to redirect to same domain from http to https如何从http重定向到同一个域到https
【发布时间】:2011-02-23 06:05:58
【问题描述】:

如何在使用 c# 编译为 dll 的类文件中的 application_beginrequest 事件中从 http 重定向到 https 到同一域。

我无法重定向到同一台服务器...任何建议...

【问题讨论】:

  • 为什么不在 IIS 设置中做呢? (对于 IIS 7/7.5,这将在 web.config 中。)
  • @Richard Ardman的答案可以在web.config中完成吗?以及如何?
  • @Lieven: 是的,在 UI 中查看它,看看它对web.config 文件所做的更改(如果在全局级别完成,它将在全局 web.config 中当然)。

标签: c# redirect https


【解决方案1】:
//Check if page is running under https. If not redirect to secure page...
if ((!HttpContext.Current.Request.IsSecureConnection))
{
    HttpContext.Current.Response.Redirect("https://" + Context.Request.Url.Host + Context.Request.Url.PathAndQuery);
}

【讨论】:

    【解决方案2】:
    if (Request.Url.ToString.ToLower.StartsWith("http://")) {
        Response.Redirect(Request.Url.ToString.Replace("http://", "https://"));
    }
    

    【讨论】:

      猜你喜欢
      • 2015-12-02
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2016-09-02
      • 1970-01-01
      • 2016-01-30
      • 1970-01-01
      • 2021-07-30
      相关资源
      最近更新 更多