登陆页为:SignIn.aspx
在asp.net配置程序配置如下:
用户名 密码 角色 进入的目录或文件
admin admin Admin ~/Admin/Default.aspx (只有admin可访问Admin文件夹)
user1 user1 user ~/Default.aspx (user可访问除Admin文件夹外的文件)
111 111 没设置属于哪个角色 和匿名用户什么都看不到我的写法怎么不可以?
根web.config:
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="SignIn.aspx" protection="Validation" path="/" timeout="300"/>
</authentication>
<authorization>
<allow roles="user" />
<deny users="*" />
</authorization>
<roleManager enabled="true"/>
<location path="Admin/Default.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>SignIn.aspx.cs文件:
protected void Button1_Click(object sender, EventArgs e)
{
if (Membership.ValidateUser(user, password))
{
if (Request.QueryString["ReturnUrl"] != null)
{ FormsAuthentication.RedirectFromLoginPage(user, false); }
else
{
FormsAuthentication.SetAuthCookie(user, false);
} }
else
{
Response.Write("Invalid UserID and Password");
}
}
}SignIn.aspx文件里面:
<asp:LoginView ID="loginArea" runat="server" Visible="true">
<AnonymousTemplate>
<asp:Login ID="login1" runat="server" DestinationPageUrl="~/Default.aspx">
<LayoutTemplate>
---------
<LoggedInTemplate>
xxx
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup Roles="user">
<ContentTemplate>
normal user
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
-------------------
为什么有三种用户登陆都显示<LoggedInTemplate>里面的XXX?
应该这么写啊?
DestinationPageUrl 属性指定当登录尝试成功时显示的页面。那不同类型的用户要去的页面不一样啊。这个属性是那种用户成功登陆时显示的页面啊?
在asp.net配置程序配置如下:
用户名 密码 角色 进入的目录或文件
admin admin Admin ~/Admin/Default.aspx (只有admin可访问Admin文件夹)
user1 user1 user ~/Default.aspx (user可访问除Admin文件夹外的文件)
111 111 没设置属于哪个角色 和匿名用户什么都看不到我的写法怎么不可以?
根web.config:
<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="SignIn.aspx" protection="Validation" path="/" timeout="300"/>
</authentication>
<authorization>
<allow roles="user" />
<deny users="*" />
</authorization>
<roleManager enabled="true"/>
<location path="Admin/Default.aspx">
<system.web>
<authorization>
<allow roles="Admin"/>
<deny users="*"/>
</authorization>
</system.web>
</location>SignIn.aspx.cs文件:
protected void Button1_Click(object sender, EventArgs e)
{
if (Membership.ValidateUser(user, password))
{
if (Request.QueryString["ReturnUrl"] != null)
{ FormsAuthentication.RedirectFromLoginPage(user, false); }
else
{
FormsAuthentication.SetAuthCookie(user, false);
} }
else
{
Response.Write("Invalid UserID and Password");
}
}
}SignIn.aspx文件里面:
<asp:LoginView ID="loginArea" runat="server" Visible="true">
<AnonymousTemplate>
<asp:Login ID="login1" runat="server" DestinationPageUrl="~/Default.aspx">
<LayoutTemplate>
---------
<LoggedInTemplate>
xxx
</LoggedInTemplate>
<RoleGroups>
<asp:RoleGroup Roles="user">
<ContentTemplate>
normal user
</ContentTemplate>
</asp:RoleGroup>
</RoleGroups>
-------------------
为什么有三种用户登陆都显示<LoggedInTemplate>里面的XXX?
应该这么写啊?
DestinationPageUrl 属性指定当登录尝试成功时显示的页面。那不同类型的用户要去的页面不一样啊。这个属性是那种用户成功登陆时显示的页面啊?
应该和vs2003中的form控制差不多吧
//生成验证票
FormsAuthenticationTicket ticket = new FormsAuthenticationTickey(1,user,DateTime.Now,DataTime.Add(new TimeSpan(0,0,10,0),false,role));
//encrypt
string encrypt = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,encrypt);
cookie.Expires = DateTime.Now.Add(new TimeSpan(0,10,0,0));
Response.Cookie.Add(cookie);
string redirectUrl = FormsAuthentication.GetRedirectUrl(FormsAuthentication.FormsCookieName,false);
Response.Redirect(redirectUrl);你先试试下面的代码 待续。