在response.redirect中强制https

Joh*_*lan 4 asp.net https

我想重定向到强制https的页面:

例如

Response.Redirect("~/Login.aspx");
Run Code Online (Sandbox Code Playgroud)

我想重定向到

 https://myserver/Login.aspx
Run Code Online (Sandbox Code Playgroud)

我怎么能强迫https?

Joh*_*lan 5

谢谢Silky让我开始.

我结束了

  var url = String.Format("https://{0}{1}", 
      Request.ServerVariables["HTTP_HOST"] ,
      ResolveUrl("~/Login.aspx"));

      Response.Redirect(url);
Run Code Online (Sandbox Code Playgroud)

  • 请注意,您可以通过以下方式获取主机:this.Request.Url.Host (3认同)