如何在 ASP.Net 应用程序中使用 HTTPS

发布于 2024-07-13 03:23:28 字数 77 浏览 5 评论 0 原文

我想在 ASP.NET Web 应用程序中使用 HTTPS,但仅限于 Login.aspx 页面。

如何才能做到这一点?

I want to use HTTPS in my ASP.NET web application, but only for the Login.aspx page.

How can this be accomplished?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

卸妝后依然美 2024-07-20 03:23:28
  1. 首先获取或创建证书

  2. http://www.codeproject.com/Articles/7206/Switching-Between-HTTP-and-HTTPS-Automatically-Ver。 有关设置的说明,请参阅文章。

  3. 将 secureWebPages 标签添加到 web.config

    <前><代码><配置>;
    ...

    ...

    ...
    <系统.web>
    ...


  4. 添加用于 https 协议的文件和目录:

     
          <文件路径=“Login.aspx”/> 
          <文件路径=“Admin/Calendar.aspx”忽略=“True”/> 
          <文件路径=“Members/Users.aspx”/> 
          <目录路径=“管理员”/> 
          <目录路径=“成员/安全”/> 
        
      

希望这有帮助!

  1. First get or create a certificate

  2. Get the SecureWebPageModule module from http://www.codeproject.com/Articles/7206/Switching-Between-HTTP-and-HTTPS-Automatically-Ver. Instructions for setup can be found in the article.

  3. Add secureWebPages tag to web.config

    <configuration>
        ...
        <secureWebPages enabled="true">
            ...
        </secureWebPages>
        ...
        <system.web>
            ...
        </system.web>
    </configuration>
    
  4. Add files and directories to be use for https protocol:

    <secureWebPages enabled="true">
        <file path="Login.aspx" />
        <file path="Admin/Calendar.aspx" ignore="True" />
        <file path="Members/Users.aspx" />
        <directory path="Admin" />
        <directory path="Members/Secure" />
    </secureWebPages> 
    

Hope this helps!

ˇ宁静的妩媚 2024-07-20 03:23:28

您可以发布自己的证书,也可以购买一份。 需要注意的是,根据公司的不同,购买证书意味着它已经存储在大多数浏览器的证书存储中。 您自行发布的证书不会,您的用户将必须采取额外的步骤来安装您的证书。

您没有说明您使用的 IIS 版本,但这里是IIS 6 的一些详细说明

您可以购买相对便宜的证书,也可以选择大公司(verisign)并获得扩展验证证书,该证书会将 IE 中的地址栏变成绿色。 这也是一个有点严格的验证过程并且需要时间。

如果您知道将访问您网站的所有用户,那么安装您自己的网站就没有问题。 然而,对于一个有匿名用户(你不知道)的开放网站,最好购买一个已经在大多数主要浏览器、证书商店中使用的网站。

您可以通过 IIS 启用 SSL,并且仅在您的 login.aspx 页面上需要它,而在其余页面上则不需要。

You can publish your own certificate or you can purchase one. The caveat is that purchasing one, depending on the company, means that it's already stored in the certificate store for most browsers. Your self published one will not be and your users will have to take the extra step of installing your cert.

You don't say what version of IIS you're using, but here are some detailed instructions for IIS 6

You can purchase relatively cheap certs or you can go with the big boys (verisign) and get an extended validation certificate which turns your address bar in IE, green. It's also a somewhat rigorous validation process and takes time.

If you know all of the users that will be hitting your website, there's no problem with installing your own. However, for an open website with anonymous users (that you don't know), it's probably best to purchase one that is already in most major browsers, certificate stores.

You can enable SSL via IIS and require it for only your login.aspx page and not for the rest.

ζ澈沫 2024-07-20 03:23:28

设置/安装 SSL 后,您希望在登录页面上执行某种重定向到 https://。 然后无论用户在验证后发送到哪个页面,它都可以是 http://。

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    If Request.IsSecureConnection = False And _
        Not Request.Url.Host.Contains("localhost") Then

        Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"))
    End If
End Sub

这可能更容易在母版页或您需要 https 的所有页面上实现。 通过检查“localhost”,您将避免在测试环境中出现错误(除非您的测试服务器有其他名称而不是检查该名称:“mytestservername”)。

After you get SSL setup/installed, you want to do some sort of redirect on the login page to https://. Then whatever page the user is sent to after validation, it can just be http://.

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    If Request.IsSecureConnection = False And _
        Not Request.Url.Host.Contains("localhost") Then

        Response.Redirect(Request.Url.AbsoluteUri.Replace("http://", "https://"))
    End If
End Sub

This may be easier to implement on a master page or just all the pages you require https. By checking for "localhost" you will avoid getting an error in your testing environment (Unless your test server has another name than check for that: "mytestservername").

时光瘦了 2024-07-20 03:23:28

免责声明 - 我参与了该项目的开发

我建议使用 http:// nuget.org/packages/SecurePages/ 它使您能够保护特定页面或使用正则表达式定义匹配项。 它还将强制所有不匹配正则表达式或直接指定的页面返回 HTTP。

您可以通过 NuGet 安装它:Install-Package SecurePages

文档位于:https://github.com/webadvanced/Secure-Page-manager-for-asp.net#secure-pages

简单用法:

SecurePagesConfiguration.Urls.AddUrl("/cart");

SecurePagesConfiguration.Urls.AddRegex(@"(.*)account", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);

disclaimer - I was involved in the development of this project

I would recommend using http://nuget.org/packages/SecurePages/ It gives you the ability to secure specific pages or use Regex to define matches. It will also force all pages not matching the Regex or directly specified back to HTTP.

You can install it via NuGet: Install-Package SecurePages

Docs are here: https://github.com/webadvanced/Secure-Page-manager-for-asp.net#secure-pages

Simple Usage:

SecurePagesConfiguration.Urls.AddUrl("/cart");

or

SecurePagesConfiguration.Urls.AddRegex(@"(.*)account", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
∞梦里开花 2024-07-20 03:23:28

您可以在 IIS 配置中启用 HTTPS,但除非您获取 SSL 证书并将其插入 IIS,否则它不会“安全”。 确保您已打开端口 443。

You can enable HTTPS in your IIS config, but it won't be "secure" unless you acquire an SSL Certificate and plug it into IIS. Make sure you have port 443 open.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文