c# – 如何使用SSL证书保护登录和成员区域?

前端之家收集整理的这篇文章主要介绍了c# – 如何使用SSL证书保护登录和成员区域?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
背景:我有一个asp.net webapplication项目,应该包含一个公共区域和一个成员区域.现在我想实现SSL解密以保护客户端和服务器之间的通信. (在大学我们有一个不安全的无线网络,你可以使用wlan嗅探器来读取用户名/密码.我不想让我的应用程序出现这个安全问题,所以我想到了一个ssl decription)

该应用程序在IIS 7.5上运行.是否有可能有一个具有不安全页面的Web应用程序(如公共区域)和安全区域(如成员区域,需要登录)?如果是,我如何重新确定这些区域之间的沟通?

例:
我的webapp托管在http://foo.abc上.
我有http://foo.abc/default.aspx和http://foo.abc/foo.aspx等网页.

在同一个项目中有一个像/member/default.aspx这样的页面,它受页面http://foo.abc/login.aspx上的登录保护.

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

我怎样才能做到这一点?我刚刚了解了如何在IIS 7.5中创建SSL证书以及如何将这样的绑定添加到webapp.如何告诉我的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”).

原文链接:https://www.f2er.com/csharp/244488.html

猜你在找的C#相关文章