gpt4 book ai didi

c# - 如何使用 SSL 证书保护登录和成员(member)区?

转载 作者:太空狗 更新时间:2023-10-29 21:25:33 27 4
gpt4 key购买 nike

背景:我有一个 asp.net webapplication 项目,它应该包含一个 public 和一个 member 区域。现在我想实现一个 SSL 解密来保护客户端和服务器之间的通信。 (在大学里我们有一个不安全的无线网络,你可以使用 wlan 嗅探器来读取用户名/密码。我不想让我的应用程序有这个安全问题,所以我想到了一个 ssl 描述)

该应用程序在 IIS 7.5 上运行。是否可以有一个具有不安全页面(如公共(public)区域)和安全区域(如成员(member)区域,需要登录)的 webapp?如果是,我如何才能实现这些区域之间的通信?

示例:我的网络应用托管在 http://foo.abc 上.我有类似 http://foo.abc/default.aspx 的页面和 http://foo.abc/foo.aspx .

在同一个项目中有一个类似/member/default.aspx的页面受页面登录保护 http://foo.abc/login.aspx .

所以我需要为页面 /login.aspx 实现 SSL和 /member/ 中的所有页面

我该怎么做?我刚刚发现如何在 IIS 7.5 中创建 SSL 证书以及如何将此类绑定(bind)添加到 Web 应用程序。如何告诉我的 webapp 应该使用 https 而不是 http 调用哪个页面。那里的最佳做法是什么?

最佳答案

从这里How to use HTTPS in an ASP.Net Application

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").

关于c# - 如何使用 SSL 证书保护登录和成员(member)区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2393114/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com