asp.net 中 Forms驗証

web.config
    <authentication mode="Forms">
      <forms loginUrl="Login.aspx"
             protection="All"
             timeout="30"
             name=".ASPXAUTH"
             path="/"
             requireSSL="false"
             slidingExpiration="true"
             defaultUrl="default.aspx"
             cookieless="UseDeviceProfile"
             enableCrossAppRedirects="false" />
    </authentication>

所有用戶必須登陸
    <authorization>
      <deny users="?" />
    </authorization>
允許所有用戶不需要登陸
<allow users="*"/>

指定用戶權限
<allow users="Admin"/>
<deny users="*"/>

指定目錄裡面程序權限
<location path ="Public">
            <system.web>
                <authorization>
<allow users="*"/>
</authorization>
            </system.web>
       </location>

<location path ="ManageSys">
            <system.web>
       <authorization>
<allow users="Admin"/>
<deny users="*"/>
</authorization>
            </system.web>
       </location>

指定某個具體化程序
<location path ="ManageSys/Auditing.aspx">

.cs程序中
 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(this.TextBox1.Text, false);
轉入到程序打開的頁面

System.Web.Security.FormsAuthentication.SetAuthCookie(this.TextBox1.Text, false);
Response.Redirect("Default.aspx");
轉入到指定的頁面

if (User.Identity.IsAuthenticated)
{
                Response.Write("已經登陸");
}
具體某個程序裡面判斷是否登陸

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

原文地址:https://www.cnblogs.com/cnaspnet/p/532071.html