【问题标题】:ASP.NET - Check for development machine or serverASP.NET - 检查开发机器或服务器
【发布时间】:2011-08-05 07:27:10
【问题描述】:

我有一个正在开发的 https 网站。开发机器不支持 https,因此给我错误。有什么方法可以识别 https 是否适用于当前环境。我的应用程序发送了一封电子邮件,其中将 http 替换为 https。我想检查一下。

【问题讨论】:

  • 我可以使用 if (Request.ClientCertificate != null && Request.ClientCertificate.IsPresent)

标签: c# .net asp.net https request


【解决方案1】:
if(Request.IsLocal)

这会返回Gets a value indicating whether the request is from the local computer.

if(Request.IsSecureConnection)

这会返回Gets a value indicating whether the HTTP connection uses secure socckets (this is, HTTPS).

【讨论】:

    【解决方案2】:

    您实际上可以在您的开发机器上安装自签名证书。浏览器会抛出一个抖动,直到您接受它作为异常,但它确实允许您在 HTTP 和 HTTPS 场景中测试您的站点/应用程序。

    【讨论】:

      【解决方案3】:

      在您的 web.config 文件中使用配置设置。

      使用 web.config 转换将值设置为在将其部署到生产环境时使用 https。

      或者,如果问题是您使用集成的 cassini Visual Studio 网络服务器在本地计算机上进行开发,您可以尝试改用 IIS Express。

      【讨论】:

        猜你喜欢
        • 2010-09-21
        • 1970-01-01
        • 2011-03-30
        • 2023-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-06
        • 1970-01-01
        相关资源
        最近更新 更多