Membershipprovider:会话结束时自动注销
我在让我的网站在会话结束(用户关闭浏览器)时自动注销经过身份验证的用户时遇到一些问题。
这是我在 web.config 中的内容:
<authentication mode="Forms">
<forms name="AuthCookie" protection="All" loginUrl="~/default.aspx" path="/" cookieless="UseCookies" timeout="2592000"/>
</authentication>
<authorization>
<allow users="?" />
</authorization>
<membership defaultProvider="ASPPGSqlMembershipProvider" userIsOnlineTimeWindow="20">
<providers>
<clear />
<add name="AspNetSqlMemberShipProvider" applicationName="umbraco4" type="System.Web.Security.SqlMembershipProvider" connectionStringName="UmbracoDb" requiresUniqueEmail="true" enablePasswordReset="true" enablePasswordRetrieval="false"/>
<add name="UsersMembershipProvider" applicationName="umbraco4" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" />
<add name="ASPPGSqlMembershipProvider" applicationName="umbraco4"
passwordStrengthRegularExpression="" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
forumUpfileFolderPath="D:\www\files"
type="ASPPG.MembershipProviders.ASPPGSqlMembershipProvider, ASPPGSiteIntegrationPackage"/>
</providers>
</membership>
这是我登录用户的方式:
if (Membership.ValidateUser(txtUserName.Text, txtPasssword.Text)) {
HttpCookie cookie = FormsAuthentication.GetAuthCookie(txtUserName.Text, false);
cookie.Expires = DateTime.Now.AddDays(1);
cookie.Domain = ConfigurationManager.AppSettings["Level2DomainName"];
HttpContext.Current.Response.Cookies.Add(cookie);
Response.Redirect(Request.Url.ToString());
}
当我关闭浏览器时,用户仍然处于登录状态。 如何让网站通过选项忘记用户,从而忘记用户自己可以决定网站是否应该记住?
预先感谢:)
M
I have some problems with getting my website to log out the authenticated user automatically when the session ends (the user closes the browser).
This is what I have in my web.config:
<authentication mode="Forms">
<forms name="AuthCookie" protection="All" loginUrl="~/default.aspx" path="/" cookieless="UseCookies" timeout="2592000"/>
</authentication>
<authorization>
<allow users="?" />
</authorization>
<membership defaultProvider="ASPPGSqlMembershipProvider" userIsOnlineTimeWindow="20">
<providers>
<clear />
<add name="AspNetSqlMemberShipProvider" applicationName="umbraco4" type="System.Web.Security.SqlMembershipProvider" connectionStringName="UmbracoDb" requiresUniqueEmail="true" enablePasswordReset="true" enablePasswordRetrieval="false"/>
<add name="UsersMembershipProvider" applicationName="umbraco4" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" />
<add name="ASPPGSqlMembershipProvider" applicationName="umbraco4"
passwordStrengthRegularExpression="" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
forumUpfileFolderPath="D:\www\files"
type="ASPPG.MembershipProviders.ASPPGSqlMembershipProvider, ASPPGSiteIntegrationPackage"/>
</providers>
</membership>
This is how I log in the user:
if (Membership.ValidateUser(txtUserName.Text, txtPasssword.Text)) {
HttpCookie cookie = FormsAuthentication.GetAuthCookie(txtUserName.Text, false);
cookie.Expires = DateTime.Now.AddDays(1);
cookie.Domain = ConfigurationManager.AppSettings["Level2DomainName"];
HttpContext.Current.Response.Cookies.Add(cookie);
Response.Redirect(Request.Url.ToString());
}
When I close the browser, the user is still logged in. How do I make the website forget the user through an option, so the user himself can decide if the website should remember or not?
Thanks in advance :)
M
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于不想被“记住”的用户,您是否尝试过不设置 cookie.Expires 或至少将其设置为 DateTime.MinValue ?
来自 MSDN:
Have you tried NOT setting the
cookie.Expires
or at least setting it toDateTime.MinValue
for user's that don't want to be 'remembered'?From MSDN: