简体   繁体   中英

ASP.NET Code blocks are not supported in this context Site.master

Im trying to write some code in my master page to check if a user is logged in. Here is the block of code

            <div class="navbar-collapse collapse">
                <asp:LoginView runat="server" ViewStateMode="Disabled">
                    <% 

                    if (Session["UserID"] == null) {
                    %>
                    <AnonymousTemplate>
                        <ul class="nav navbar-nav navbar-right">
                            <li><a runat="server" href="~/Account/Register">Register</a></li>
                            <li><a runat="server" href="~/Account/Login">Log in</a></li>
                        </ul>
                    </AnonymousTemplate>
                    <%
                    } else  { 
                    %>
                    <LoggedInTemplate>
                        <ul class="nav navbar-nav navbar-right">
                            <li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Session["UserID"] %>!</a></li>
                            <li>
                                <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
                            </li>
                        </ul>
                    </LoggedInTemplate>
                    <%
                    }
                    %>
                </asp:LoginView>
            </div>

Code blocks like

<% if (Session["UserID"] == null) {
                %> ...

Are not allowed inside an <asp: runat="server">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM