【问题标题】:Can I change the FormsAuthentication cookie name?我可以更改 FormsAuthentication cookie 名称吗?
【发布时间】:2011-10-03 11:11:57
【问题描述】:

我可以更改 FormsAuthentication cookie 名称吗?

如果是,怎么做?

我遇到的问题是,当我有两个 Web 应用程序部署在同一个域中时,当任何人登录时,第二个应用程序将自动注销,因为它们使用相同的身份验证的 cookie 名称。

【问题讨论】:

标签: asp.net cookies forms-authentication


【解决方案1】:

您可以在 web.config 文件中进行调整:

<authentication mode="Forms">
  <forms name=".CookieName" loginUrl="LoginPage.aspx" />
</authentication>

【讨论】:

  • 对于任何想知道这一点的人,默认的 cookie 名称是“.ASPXAUTH”
  • .CookieName 和 .ASPXAUTH 有什么区别?
  • @BobSwager 前者长了几个字符。
【解决方案2】:

是的,您可以在forms 元素下的web.config 元素的authentication 元素下指定cookie 名称。

<authentication mode="Forms">
    <forms name="RoleBasedAuthenticationCookiename" loginUrl="~/Login.aspx" defaultUrl="~/Default.aspx">
    </forms>
</authentication>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-14
    • 2011-05-31
    • 2016-09-13
    • 2012-01-17
    • 2018-01-20
    • 1970-01-01
    • 2021-11-20
    相关资源
    最近更新 更多