<asp:Label id="lbSf" style="Z-INDEX: 104; LEFT: 355px; POSITION: absolute; TOP: 133px" runat="server"></asp:Label>
<asp:Button id="btnLogout" style="Z-INDEX: 105; LEFT: 261px; POSITION: absolute; TOP: 192px"
runat="server" Text="注销" Width="101px"></asp:Button></FONT>
</form>
</body>
后置代码
private void Page_Load(object sender, System.EventArgs e)
{
this.lbUser.Text = User.Identity.Name;
if (User.IsInRole("Admin"))
this.lbSf.Text = "Admin";
else
this.lbSf.Text = "User";
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnLogout.Click = new System.EventHandler(this.btnLogout_Click);
this.Load = new System.EventHandler(this.Page_Load);
}
#endregion
private void btnLogout_Click(object sender, System.EventArgs e)
{
FormsAuthentication.SignOut();//注销票
Response.Redirect("login.aspx",true);返回login.aspx页面
}
webconfig配置如下
<authentication mode="Forms" >
<forms name=".SecurityDemo" loginUrl="login.aspx">//.SecurityDemo为cookie名,
</forms>
</authentication>
<authorization>
<deny users="?"/> //拒绝所有匿名用户
<allow roles="admins"/>//允许管理级别用户访问
</authorization>
自我感觉ASP写多了,一般是用session进行判断用户是否合法,但在一个ASP.NET项目中使用身份验证,基本上所有页面都要验证才能访问,感觉有点迁强.但可以在web.config页面对指定的页面设置权限,设置代码如下
<location path="admin.aspx">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
如果只有几个页面设置如上代码,感觉还可以接受.但页面多了岂不是要把人累死呀..
可能是小的项目做多了,大项目没接触过.请高手给指点具体用途呀.不甚感激.
http://www.cnblogs.com/paleyyang/archive/2006/10/21/536147.html
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




