在网站中增加权限设置,FormsAuthentication 例

首先需要在  <system.web>节中加入

<authentication mode="Forms">
<!--设置名字为AdminUsers,默认转向adminlogin.aspx,过期时间60分钟-->
<forms name="AdminUsers" loginUrl="/Admin/Login.aspx" timeout="60"></forms>

</authentication>

然后在需要加权限的地方<system.web>加入

<authorization>
<deny users="?"/> 拒绝所有匿名
<allow users="*"/>允许所有用户
</authorization>

在验证通过后增加票证,放入cookies。

System.Web.Security.FormsAuthentication.SetAuthCookie("admin", false);

“admin” 为cookies名称,false 为是否创建持久cookies,false为回话cookies

(一般还会同时创建一个session)

登出销毁票证

System.Web.Security.FormsAuthentication.SignOut();

销毁session

posted @ 2013-11-19 09:42  武二郎  阅读(260)  评论(0编辑  收藏  举报