您可以随心所欲地授权您的用户。FormAuthentication 用于设置会话身份和身份验证 cookie,允许用户在注销或会话过期之前保持登录状态。您无需使用成员资格提供程序即可使用 FormsAuthentication。听起来您只是在复制此功能。
...do your authentication against your DB or Active Directory
if (Request.QueryString["ReturnUrl"] != null)
{
FormsAuthentication.RedirectFromLoginPage(userName.Text, false);
}
else
{
FormsAuthentication.SetAuthCookie(userName.Text, false);
}
然后你需要在web.config中设置使用它
<system.web>
<authentication mode="Forms">
<forms loginUrl="Login.aspx"
protection="All"
timeout="30"
name="my-auth-cookie"
path="/"
requireSSL="false"
slidingExpiration="true"
defaultUrl="default.aspx" />
</authentication>
</system.web>
您可以获得自己授权的所有好处,而不必实施 cookie 基础架构。请注意,由于您的网站只需要在编辑时授权,因此您需要设置允许每个人阅读所有页面的权限,并实现您自己的逻辑,以便在他们想要编辑时将他们重定向到登录页面。
更多信息在这里。