C#更改为http

C#更改为http,c#,asp.net,C#,Asp.net,我有以下代码: if (Request.Url.AbsolutePath == "/Text12.aspx") protected void Application_BeginRequest(Object sender, EventArgs e) { if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.E

我有以下代码:

      if (Request.Url.AbsolutePath == "/Text12.aspx")
protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
    {
      Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
      + HttpContext.Current.Request.RawUrl);
    }
}
我喜欢做的是让http

    http://www.mysitename/Text12.aspx 
无论用户是否键入

    www.mysitename/Text12.aspx or 
    https://www.mysitename/Text12.aspx or 
    http://www.mysitename/Text12.aspx

我想试着回答。假设您希望用户始终使用http。在我的一些应用程序中,我通过以下代码强制使用https:

      if (Request.Url.AbsolutePath == "/Text12.aspx")
protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
    {
      Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
      + HttpContext.Current.Request.RawUrl);
    }
}
这也应该反过来解决:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
    if (HttpContext.Current.Request.IsSecureConnection.Equals(true) && HttpContext.Current.Request.IsLocal.Equals(true))
    {
       Response.Redirect("http://" + Request.ServerVariables["HTTP_HOST"]
       + HttpContext.Current.Request.RawUrl);
    }
}
//编辑:
请注意,我已将Islocal设置为true,因此只有在本地调用或在您的开发人员机器上调用时才会触发。您仍然需要使其符合您的需要,或者完全删除该条件。

但实际问题是什么?你想干什么?这看起来就像是字符串操作。将它们重定向到URL路径会有帮助吗?所以你想强制http,不管用户是否使用https?我的直觉告诉我,调整DNS可能会解决这个问题