求段页面权限认证代码 最好比较简单的要求单个用户可添加多个角色,最好附上表的结构,越清楚明白越好啊!呵呵!终于等到中秋节了,祝大家中秋快乐! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大概在这里找C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallMembership.sql, InstallProfile.SQL, InstallRoles.sql 表结构,针对复杂--------用户表 userinfo(uid,uname,……) 角色表 role(rid,rdesc,……)用户角色关系表 userrole(uid,rid)权限表 popeom(pid,pdesc,……)//可以定义到页面级或者控件级,一般写死权限角色表 popeomrole(pid,rid)--------------------------页面认证----if(!ispostback){ if(Session["userrole"]!=null) { List<string> listUserRole = Session["userrole"] as List<string>; if(listUserRole.contains("权限ID"))//登录成功后把用户的角色放到 Session或者其他变量中,个人习惯将角色放到泛形中 List<string> listUserRole; { 有权限; } else { 没权限; } else { 没有登录,返回首页 }} 定力推荐ms 的 membership 这里有整套的权限控制 NET权限管理系统 用户表 userinfo(uid,uname,roleId,...) 角色表 role(rid,rname,...)if(!ispostback){ if(Session["role"]==null) {Response.Redirdct("");}}http://www.51aspx.com/S/%E6%9D%83%E9%99%90%E7%AE%A1%E7%90%86.html ASP.NET常用身份验证:windows 和Forms。window常用于同一个域的用户,比喻公司内部网站。Forms是一种基于Cookie的认证方式。由于Forms 的认证方式更普遍。以下是自己定制Forms认证的方式:一:修改配置文件:设置认证方式。<authentication mode="Forms"> <forms name="test" loginUrl="Default.aspx" defaultUrl="index.aspx" protection="All"></forms> </authentication>二:设置网站文件的角色权限。例如:只有admin能访问admin目录下的文件<location path="admin"> <system.web> <authorization> <allow roles="admin"/> <deny users="*"/> </authorization> </system.web> </location>三:设置自定义的角色提供者。<roleManager defaultProvider="MyRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" > <providers> <clear /> <add name="MyRoleProvider" type="MyRoleProvider" writeExceptionsToEventLog="false" /> </providers > </roleManager >四:实现MyRoleProvider类。public class MyRoleProvider : RoleProvider{ public override string[] GetRolesForUser(string username) { FormsIdentity Id = HttpContext.Current.User.Identity as FormsIdentity; if (Id != null) { return Id.Ticket.UserData.Split(new Char[] { ',' }); } return null; }/****** 实现RoleProvider的抽象方法。******/}五:设置用户的票证。其中包含用户的角色信息。if (/*用户合法的情况*/) { string userRole = "admin";//模拟角色可以在数据库中设置 FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, TextBox1.Text, DateTime.Now, DateTime.Now.AddMinutes(1), false, userRole);//用户角色 string emTicket = FormsAuthentication.Encrypt(ticket); HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, emTicket); Response.Cookies.Add(UserCookie); string[] user = new string[] { TextBox1.Text }; Context.Response.Redirect(FormsAuthentication.GetRedirectUrl(this.TextBox1.Text, false)); } 页面中的产品信息部分,怎样管理比较好? 检索条件都没有填写,直接点击查询按钮,分页无效 20天做好的网站,大家帮忙看看提提建议,谢谢 水晶报表中如何显示图片? vs2005 treeview和xml绑定后 url怎么设置 Session过期怎么跳转 javascript控制treeview的checkbox? 看透了,我们需要属于自己的,量身定制的datagrid控件!!! 我得水晶老是这样报错,好烦人啊。!!!!!!!! 想用vb.net做一个上传到服务器某个文件夹的程序..请大家帮忙... 如何获取上一页的状态 访问用户控件的属性
--------
用户表 userinfo(uid,uname,……)
角色表 role(rid,rdesc,……)
用户角色关系表 userrole(uid,rid)
权限表 popeom(pid,pdesc,……)//可以定义到页面级或者控件级,一般写死
权限角色表 popeomrole(pid,rid)
--------------------------
页面认证
----
if(!ispostback)
{
if(Session["userrole"]!=null)
{
List<string> listUserRole = Session["userrole"] as List<string>;
if(listUserRole.contains("权限ID"))//登录成功后把用户的角色放到 Session或者其他变量中,个人习惯将角色放到泛形中 List<string> listUserRole;
{
有权限;
}
else
{
没权限;
}
else
{
没有登录,返回首页
}
}
角色表 role(rid,rname,...)
if(!ispostback)
{
if(Session["role"]==null)
{Response.Redirdct("");}
}http://www.51aspx.com/S/%E6%9D%83%E9%99%90%E7%AE%A1%E7%90%86.html
<forms name="test" loginUrl="Default.aspx" defaultUrl="index.aspx" protection="All"></forms>
</authentication>二:设置网站文件的角色权限。例如:只有admin能访问admin目录下的文件<location path="admin">
<system.web>
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>三:设置自定义的角色提供者。<roleManager defaultProvider="MyRoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieName=".ASPROLES"
cookieTimeout="30"
cookiePath="/"
cookieRequireSSL="false"
cookieSlidingExpiration="true"
cookieProtection="All" >
<providers>
<clear />
<add name="MyRoleProvider"
type="MyRoleProvider"
writeExceptionsToEventLog="false" />
</providers >
</roleManager >四:实现MyRoleProvider类。public class MyRoleProvider : RoleProvider
{
public override string[] GetRolesForUser(string username)
{
FormsIdentity Id = HttpContext.Current.User.Identity as FormsIdentity;
if (Id != null)
{
return Id.Ticket.UserData.Split(new Char[] { ',' });
}
return null; }/****** 实现RoleProvider的抽象方法。******/}五:设置用户的票证。其中包含用户的角色信息。if (/*用户合法的情况*/)
{
string userRole = "admin";//模拟角色可以在数据库中设置
FormsAuthenticationTicket ticket =
new FormsAuthenticationTicket(1,
TextBox1.Text,
DateTime.Now,
DateTime.Now.AddMinutes(1),
false,
userRole);//用户角色
string emTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, emTicket);
Response.Cookies.Add(UserCookie);
string[] user = new string[] { TextBox1.Text };
Context.Response.Redirect(FormsAuthentication.GetRedirectUrl(this.TextBox1.Text, false));
}