开发者

hide log off link once logged in

开发者 https://www.devze.com 2023-03-19 09:35 出处:网络
I need to display a login link and once they are logged in i need the link to display as log off. here is what i have so far:

I need to display a login link and once they are logged in i need the link to display as log off.

here is what i have so far:

<div class="account-links">

<a href="<%=Page.ResolveUrl("~/logout.aspx")%>" class="ico-logout">
<%=GetLocaleResourceString("Account.Logout")%></a>

<% if (NopContext.Current.User != null && NopContext.Current.User.IsAdmin)
               { %>
<a href="<%=Page.ResolveUrl("~/administration/")%>" class="ico-admin">
  <%=GetLocaleRes开发者_如何转开发ourceString("Account.Administration")%></a>
    <%} %>


</div>
    <div class="header-links">
        <ul>
            <asp:LoginView ID="topLoginView" runat="server">
                <AnonymousTemplate>

                </AnonymousTemplate>
                <LoggedInTemplate>
                    <li>
                        <a href="<%= SEOHelper.GetMyAccountUrl()%>" class="account"><%=Page.User.Identity.Name %></a>
                        <% if (NopContext.Current.IsCurrentCustomerImpersonated)
                           { 
                        %>
                        <span class="impersonate">(<%=string.Format(GetLocaleResourceString("Account.ImpersonatedAs"), this.CustomerService.UsernamesEnabled ? Server.HtmlEncode(NopContext.Current.User.Username) : Server.HtmlEncode(NopContext.Current.User.Email))%>
                            -
                            <asp:LinkButton runat="server" ID="lFinishImpersonate" Text="<% $NopResources:Account.ImpersonatedAs.Finish %>"
                                ToolTip="<% $NopResources:Account.ImpersonatedAs.Finish.Tooltip %>" OnClick="lFinishImpersonate_Click"
                                CssClass="finish-impersonation"></asp:LinkButton>)</span>
                        <%} %>
                    </li>
                    <li></li>
                    <% if (this.ForumService.AllowPrivateMessages)
                       { %>
                    <li><a href="<%=Page.ResolveUrl("~/privatemessages.aspx")%>" class="ico-inbox">
                        <%=GetLocaleResourceString("PrivateMessages.Inbox")%></a>
                        <asp:Literal runat="server" ID="lUnreadPrivateMessages" />
                    </li>
                    <%} %>
                </LoggedInTemplate>
            </asp:LoginView>


Unless I've misunderstood just add a log off link to the "Logged in template" and add a click event to it and log off in the code.

I think off the top of my head

FormsAuthentication.SignOut() 

will do that

Then for the login, stick a link to your login page in your "anonymous template".


In Asp.Net MVC, there is a Request.IsAuthenticated property that you can use which checks if User.Identity.Name is not null. Hopefully there is something like this available to you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号