首先:webconfig中配置好
<appsetting>
<add key="urlLogin" value="~/Login.aspx"/>
</appsetting>
<authentication mode="Forms">
<forms protection="All" timeout="1440" loginUrl="Login.aspx" />
</authentication>
<authorization>
<allow users="*"></allow>
</authorization>
配置完成後
頁面佈局(略)
Login.aspx.cs中驗證處理過程
如果登陸驗證成功執行下面的語句
FormsAuthentication.SetAuthCookie("你想傳遞的信息", false);
Response.Redirect("~/Default.aspx");
如果登陸驗證失敗可以不作任何處理 或者作一個提示信息
其他頁,都在其頁面初始化cs代碼段加入這句話
if (!Page.User.Identity.IsAuthenticated)
{
Response.Redirect(System.Configuration.ConfigurationManager.AppSettings["urlLogin"].ToString());
return;
}
以上就是完成一個頁面的驗證登陸效果