【问题标题】:Should i declare https in web.config?我应该在 web.config 中声明 https 吗?
【发布时间】:2009-07-28 19:25:58
【问题描述】:

我想我在 https 中遗漏了一些东西......

目前我正在使用它来将所需页面从 http 重定向到 https

  If Not Request.IsSecureConnection Then
  Dim serverName As String = HttpUtility.UrlEncode(Request.ServerVariables("SERVER_NAME"))
  Dim filePath As String = Request.FilePath
  Response.Redirect(("https://" & serverName) + filePath)
  End If

我应该在 web.config 的某处声明 https 的绝对链接吗?

附言我的链接是相对的

【问题讨论】:

    标签: security https web-config


    【解决方案1】:

    您可以编写HttpModule 并将其添加到 web.config。

    【讨论】:

      【解决方案2】:

      如果您想使用静态 URL,则可以将其添加到您的网络配置中:

      <appSettings>
          <add key="url" value="http://www.yoursite.com" />
      </appSettings>
      

      之后,您可以像这样在任何您想要的地方获得该值:

      string strHost = ConfigurationManager.AppSettings.Get("url").ToString();
      

      希望这能解决您的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-12-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多