如何根据用户所在分组进行身份验证
2010-05-03 14:37
543 查看
1. 创建Login.aspx,News文件夹,BBS文件夹,在两个文件夹内分别有一个Default.aspx页面
2. 修改Web.config文件,如下:
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="Login.aspx" protection="All" path="/" timeout="30">
<credentials passwordFormat="Clear">
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="A,B" />
</authorization>
<location path="BBS">
<system.web>
<authorization>
<deny users="?,A"/>
<allow users="B"/>
</authorization>
</system.web>
</location>
<location path="News">
<system.web>
<authorization>
<deny users="?,B"/>
<allow users="A"/>
</authorization>
</system.web>
</location>
注:<location path="BBS">代表对BBS文件夹进行权限设置。允许B组用户,不允许匿名用户和A组用户登录。
创建Login.aspx
string group;
protected void btnLogin_Click(object sender, EventArgs e)
{
//从Web.config中取出连接字符串
string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from users where uname='" + txtName.Text + "'";
cmd.Connection = con;
SqlDataReader dr=cmd.ExecuteReader();
if (dr.Read())
{
if (dr[1].ToString().Equals(txtPwd.Text))
{
//group是该用户所在分组
group = dr[2].ToString();
//将该用户的分组保存进Cookie中
FormsAuthentication.RedirectFromLoginPage(group, true);
}
}
}
2. 修改Web.config文件,如下:
<authentication mode="Forms">
<forms name=".ASPXFORMSDEMO" loginUrl="Login.aspx" protection="All" path="/" timeout="30">
<credentials passwordFormat="Clear">
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
<allow users="A,B" />
</authorization>
<location path="BBS">
<system.web>
<authorization>
<deny users="?,A"/>
<allow users="B"/>
</authorization>
</system.web>
</location>
<location path="News">
<system.web>
<authorization>
<deny users="?,B"/>
<allow users="A"/>
</authorization>
</system.web>
</location>
注:<location path="BBS">代表对BBS文件夹进行权限设置。允许B组用户,不允许匿名用户和A组用户登录。
创建Login.aspx
string group;
protected void btnLogin_Click(object sender, EventArgs e)
{
//从Web.config中取出连接字符串
string conStr = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from users where uname='" + txtName.Text + "'";
cmd.Connection = con;
SqlDataReader dr=cmd.ExecuteReader();
if (dr.Read())
{
if (dr[1].ToString().Equals(txtPwd.Text))
{
//group是该用户所在分组
group = dr[2].ToString();
//将该用户的分组保存进Cookie中
FormsAuthentication.RedirectFromLoginPage(group, true);
}
}
}
相关文章推荐
- ESMTP协议如何进行身份验证
- 如何实现在程序中进行网络计算机的用户验证
- win7上运行某程序的时候,如果这个程序需要以管理员的身份运行,那么就会有“用户帐户控制”的提示:“您想允许来自...发布者的以下程序对此计算机进行更改吗?”请问,win7如何知道哪些程序需要以管理员的身份运行?
- HttModule和抽象类BasePage两种方式进行用户身份验证
- Java界面开发——登录并对用户身份进行验证
- 手机客户端和服务器通信时如何安全高效的进行身份验证
- 在进行Forms身份验证时如何将此信息映射到GenericPrincipal 和 FormsIdentity 对象?
- Java界面开发——登录并对用户身份进行验证
- 如何使用 RODC 进行身份验证过程
- 如何对Exchange SMTP身份验证记录进行分析
- 用户体验:如何对定性人物角色进行定量验证
- ASP.NET - 如何:根据模式对 ASP.NET 服务器控件进行验证
- 如何使用 Web API 来对 MVC 应用程序进行身份验证
- 在进行Forms身份验证时如何将此信息映射到GenericPrincipal 和 FormsIdentity 对象?
- 使用 Apache Shiro 为 web 应用程序进行用户身份验证
- 制作一个银行卡用户登录页面,提交后连接数据库进行登录验证,根据验证结果跳转到不同页面
- 如何根据用户银行帐户余额的多少进行显式的提交或终止?
- asp.net如何利用page事件来进行身份验证
- ISA Server 2004 Web代理服务拒绝用户再次进行身份验证
- 如何根据用户IP得到用户所在位置。