简体   繁体   English

将HTTP重定向到https的提示

[英]Proplem with redirect http to https

In ISS 7.5 i had 2 bindings: 在ISS 7.5中,我有2个绑定:

    • Type: http 类型:http
    • IP: 127.0.0.1 的IP:127.0.0.1
    • Port: 80 端口:80
    • Type: https 类型:https
    • IP: 127.0.0.1 的IP:127.0.0.1
    • Port: 443 端口:443

and I using this code redirect http to https: (code in Global.asax.cs file) 并且我使用此代码将http重定向到https:(Global.asax.cs文件中的代码)

if (HttpContext.Current.Request.IsSecureConnection.Equals(false))
{
  Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
}

It's working correctly, but after I changed the 2 bindings in IIS to: 它工作正常,但是将IIS中的2个绑定更改为:

    • Type: http 类型:http
    • IP: 127.0.0.1 的IP:127.0.0.1
    • Port: 8101 端口:8101
    • Type: https 类型:https
    • IP: 127.0.0.1 的IP:127.0.0.1
    • Port: 8102 端口:8102

It no longer redirect HTTP to HTTPS. 它不再将HTTP重定向到HTTPS。 I think this code cannot redirect from port 8101 to port 8102 and I don't know how to get port number of HTTPS in IIS by C#. 我认为这段代码无法从端口8101重定向到端口8102,而且我不知道如何通过C#获取IIS中HTTPS的端口号。 Please tell how or if you had different solution to redirect. 请告诉您如何或是否有其他重定向解决方案。

您能像这样简单地以静态方式简单地指定端口吗?

Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + ":8102" + HttpContext.Current.Request.RawUrl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM