10

我的 APS.NET 应用程序中有一个带有 AnonymousTemplate 和 LoggedInTemplate 的 LoginView。我已将 LoginStatus 控件放在 LoggedInTemplate 中,但它没有按预期工作。

这是代码

<asp:LoginView ID="LoginView1" runat="server">
    <AnonymousTemplate>
        <asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate"
            DisplayRememberMe="False" PasswordRecoveryUrl="/" 
            DestinationPageUrl="/">
        </asp:Login>
    </AnonymousTemplate>
    <LoggedInTemplate>
        You are logged in as 
        <asp:LoginName ID="LoginName1" runat="Server"></asp:LoginName>.
        <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" 
            LogoutPageUrl="/" onloggingout="LoginStatus1_LoggingOut" />
    </LoggedInTemplate>
</asp:LoginView>

所有事件处理程序都在代码隐藏文件中正确定义。

问题是,如果用户登录,他将看到他的用户名以及来自 LoginStatus 控件的注销链接。单击注销链接会使用户返回登录表单(登录和注销表单都是同一用户控件的一部分),但如果我刷新页面,用户仍处于登录状态。

我注意到如果我将 LoginStatus 控件移到 LoginView 之外,那么注销过程会按预期工作。我还注意到,当 LoginStatus 在 LoginView 中时,它不会引发注销事件。

有谁知道可能是什么问题?

4

4 回答 4

2

我在这里遇到了同样的问题。loginview 控件之外的 loginstatus 控件按需要工作。它在 loginview 控件中不起作用似乎很愚蠢。

编辑**好的,所以我忽略了我在 Sitecore 中构建此页面。显然,Sitecore 以某种方式干扰了 loginview 控件,因此必须将其添加到 web.config 中的以下部分:

  <sitecore>
    <rendering>
      <typesThatShouldNotBeExpanded>
        <type>System.Web.UI.WebControls.LoginView</type>
      </typesThatShouldNotBeExpanded>
    </rendering>
  </sitecore>

感谢其他人...

-维克多·F。

于 2011-08-26T15:28:27.980 回答
1
FormsAuthentication.SignOut()
FormsAuthentication.RedirectToLoginPage()

另外,您是否以正确的方式使用了表单身份验证,我的意思是您是否将 Web 配置放在内部目录中?

<system.web>
<authorization>
  <allow users="?"/>
</authorization>

于 2011-08-19T06:07:02.413 回答
1

I am experiencing the same problem. But my solution was to swap out the loginstatus control for a hyperlink control and have the hyperlink navigate to my home page with a querystring parameter attached like "logout=true" and then on my home page check Request.QueryString for the value and if it is not null the do this.

FormsAuthentication.SignOut();
于 2011-10-20T14:52:30.950 回答
0

你有没有试过改变你LogoutActionLogoutAction="RedirectToLoginPage"?我通常让 .NET 处理清除 cookie,这使得OnLoggingOut事件不需要。

于 2011-03-04T04:03:39.403 回答