Asp.net http和受限部分
我想问你们,因为我不确定答案 我有一个网站,Asp.NET2.0,我有一个只有经过身份验证的用户才能访问的部分。确保只有在成功验证(登录/通过)后,用户才会重定向到受限部分。但我的问题更关心的是,如果我需要在http上使用https的话。我会在Page_load方法中检查用户是否经过身份验证,是否处于适当的角色。像这样:Asp.net http和受限部分,asp.net,security,https,Asp.net,Security,Https,我想问你们,因为我不确定答案 我有一个网站,Asp.NET2.0,我有一个只有经过身份验证的用户才能访问的部分。确保只有在成功验证(登录/通过)后,用户才会重定向到受限部分。但我的问题更关心的是,如果我需要在http上使用https的话。我会在Page_load方法中检查用户是否经过身份验证,是否处于适当的角色。像这样: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ApplyAuthorizationRules();
InitData();
}
}
private void ApplyAuthorizationRules()
{
//Check if the user is logged in
if (!Page.User.Identity.IsAuthenticated)
{
Response.Redirect(NotAuthenticated.UrlToSelf());
}
//check if the user is in one of FU roles
if (!Page.User.IsInRole(Constants.ROLECLIENT))
{
Response.Redirect(NotAuthorized.UrlToSelf());
}
}
为了更好地描述,这里有my web.config设置的快照:
<identity impersonate="false" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
那么,真的有必要使用https吗
谢谢你的建议。X.授权和加密有不同的用途。如果数据是敏感的,您可能应该使用https。假设您使用了https,那么请注意,如果您使用http,则每个请求都会以明文形式发送用户名和密码。如果您想提供更多的安全性以防止凭据被嗅探,那么请使用https 还有其他一些方法,比如提供多一点保护,但一般来说,用户可能会觉得受到保护的任何东西都可以使用https
public static bool Login(string username, string password)
{
AppIdentity identity = AppIdentity.GetIdentity(username, password);
AppPrincipal principal = new AppPrincipal(identity);
HttpContext.Current.User = principal;
return identity.IsAuthenticated;
}