LoginStatus文本未正确更新 [英] LoginStatus text not updated correctly

查看:85
本文介绍了LoginStatus文本未正确更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在web.config文件中像这样放置FormsAuthentication:

 <  身份验证   模式  ="  > 
    <  表单    ="  登录"  loginUrl   /WebPages/Default.aspx?Action =登录" 
                      defaultUrl   =" /WebPages/Default.aspx?Action = Login" 
                 保护  =" 全部" 路径  /WebPages/"  / > 
<  /authentication  > 
<  授权 > 允许users = ?" <  /authorization  >  




我在主页上有一个LoginStatus控件,其中显示"Login"开头.当我单击它时,它将重定向我到登录页面.成功登录后,我返回主页.但是LoginStatus控件的LoginText尚未更新.即,它仍然显示"Login".当我第二次再次单击LoginStatus时,它将更新为注销",然后转到登录"页面.
LoginStatus控件的定义如下:

<asp:loginstatus id="LoginStatus1" runat="server" logoutaction="Redirect" logoutpageurl="~/WebPages/Default.aspx" xmlns:asp="#unknown" />



我应该怎么做才能使LoginStatus第一次自动显示正确的文本?

解决方案

您是否使用过LoginView?

 <   asp:LoginView     ID   ="     runat   =" 服务器" <   AnonymousTemplate  > 
        <   span     ="  > 欢迎您,访客
            <   asp:LoginStatus     ID   ="   runat   服务器" / <  /span  > 
    <  /AnonymousTemplate  > 
    <   LoggedInTemplate  > 
        欢迎,
        <   asp:LoginName     ID   ="   runat   服务器" / <   asp:LoginStatus     ID   ="   runat   服务器" / <  /LoggedInTemplate  >  




LoggedInTemplate 应包含LoginStatus .


也看看这个.
http://www. developer.com/net/asp/article.php/3655706/ASPNET-Tip-Using-the-LoginName-and-LoginStatus-Controls.htm [ < asp:Login ID =" ="span> runat =" 服务器" BackColor 白色" BorderColor =" BorderStyle =" 实心" BorderWidth 1像素" EnableTheming =" EnableViewState 真实" 字体名称 =" 字体大小 TitleText =" 字体粗体 错误" 宽度 =" DestinationPageUrl 〜/WebPages/Welcome.aspx" onloggedin =" VisibleWhenLoggedIn 错误" < LoginButtonStyle =" 错误" 字体名称 Verdana" 字体大小 小" / > < LayoutTemplate > < =" 0" 单元格填充 > 1" 单元格间距 =" 0" 样式 =" border-collapse:collapse;" < tr > < td > < =" 0" cellpadding > 0" 样式 =" 宽度:530px;" < tr > < td =" center" colspan 2" 样式 = " > 管理员登录< /td > < /tr > < tr > < td =" 右" 样式 字体粗细:normal;" class style1" < asp:Label ID =" runat 服务器" AssociatedControlID 用户名" < /asp:Label > < /td > < td =" 左" < asp:TextBox ID =" runat 服务器" 宽度 170像素" < /asp:TextBox > < asp:RequiredFieldValidator ID =" runat 服务器" ControlToValidate UserName" ErrorMessage =" ToolTip 用户名是必需的." ValidationGroup LoginAdmin" < > < /td > < /tr > < tr > < td =" 右" 样式 字体粗细:normal;" class style1" < asp:Label ID =" runat 服务器" AssociatedControlID 密码" ">< /asp:标签 > < /td > < td =" 左" < asp:TextBox ID =" runat 服务器" TextMode 密码" 宽度 170px" < > < asp:RequiredFieldValidator ID =" runat 服务器" ControlToValidate 密码" ErrorMessage =" ToolTip 密码是必需的." ValidationGroup LoginAdmin" > * < /asp:RequiredFieldValidator < /td > < /tr > < tr > < td =" center" colspan 2" 样式 =" 颜色:红色;" < asp:Literal ID =" runat 服务器" EnableViewState 错误" < /asp:文字 > < /td > < /tr > < tr > < td =" center" colspan > 2" > < asp:Button ID =" runat 服务器" CommandName 登录" 字体粗体 =" =" Verdana" 字体大小 小" 文本 登录" ValidationGroup LoginAdmin" onclick =" / > < /td > < /tr > < /table > < /td > < /tr > < /table > < /LayoutTemplate > < LabelStyle =" 错误" / < TitleTextStyle =" #6B696B" 字体粗体 True" ForeColor =" #FFFFFF" / > < /asp:登录 >


I have FormsAuthentication in place like this in web.config file:

<authentication mode="Forms">
    <forms name="Login" loginUrl="/WebPages/Default.aspx?Action=Login"

        defaultUrl="/WebPages/Default.aspx?Action=Login"

        protection="All" path="/WebPages/" />
</authentication>
<authorization>allow users="?" </authorization>




I have a LoginStatus control in the mainpage, which shows ''Login'' to startwith. When I click on that, it will redirect me to the login page. After logging in successfully, I go back to the main page. But the LoginText of LoginStatus control is not updated..i.e., it still shows ''Login''. When I click on the LoginStatus again for the second time, then it is updated to ''Logout'' and I go to the Login page.
The LoginStatus control is defined like this:

<asp:loginstatus id="LoginStatus1" runat="server" logoutaction="Redirect" logoutpageurl="~/WebPages/Default.aspx" xmlns:asp="#unknown" />



What should I do to get the LoginStatus to show correct text first time itself??

Did you use LoginView ?

<asp:LoginView ID="LoginView1" runat="Server">
    <AnonymousTemplate>
        <span style="font-family: Arial; font-size: 10pt;">Welcome, Guest
            <asp:LoginStatus ID="LoginStatus1" runat="Server" />
        </span>
    </AnonymousTemplate>
    <LoggedInTemplate>
        Welcome,
        <asp:LoginName ID="LoginName1" runat="Server" />
        <asp:LoginStatus ID="LoginStatus1" runat="Server" />
    </LoggedInTemplate>




The LoggedInTemplate should have LoginStatus in it.


Also have a look into this.
http://www.developer.com/net/asp/article.php/3655706/ASPNET-Tip-Using-the-LoginName-and-LoginStatus-Controls.htm[^]


Hi Abhishek,
Thanks for the reply. I tried your sample but no luck. I guess there is something to do with the Login control, which is like this:

<asp:Login ID="LoginAdmin" runat="server" BackColor="White"

                    BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px"

                        EnableTheming="True" EnableViewState="True"

                        Font-Names="Verdana" Font-Size="10pt"

                        TitleText="Admin Log In" Font-Bold="False"

                        Width="340px" DestinationPageUrl="~/WebPages/Welcome.aspx"

                        onloggedin="LoginAdmin_LoggedIn" VisibleWhenLoggedIn="False">
                    <LoginButtonStyle Font-Bold="False" Font-Names="Verdana" Font-Size="Small" />
                        <LayoutTemplate>
                            <table border="0" cellpadding="1" cellspacing="0"

                                style="border-collapse:collapse;">
                                <tr>
                                    <td>
                                        <table border="0" cellpadding="0" style="width:530px;">
                                            <tr>
                                                <td align="center" colspan="2"

                                                    style="color:White;background-color:#6B696B;font-weight:bold;">
                                                    Admin Log In</td>
                                            </tr>
                                            <tr>
                                                <td align="right" style="font-weight:normal;" class="style1">
                                                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User
                                                    Name:</asp:Label>
                                                </td>
                                                <td align="left">
                                                    <asp:TextBox ID="UserName" runat="server" Width="170px"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server"

                                                        ControlToValidate="UserName" ErrorMessage="User Name is required."

                                                        ToolTip="User Name is required." ValidationGroup="LoginAdmin">*</asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="right" style="font-weight:normal;" class="style1">
                                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                                </td>
                                                <td align="left">
                                                    <asp:TextBox ID="Password" runat="server" TextMode="Password" Width="170px"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server"

                                                        ControlToValidate="Password" ErrorMessage="Password is required."

                                                        ToolTip="Password is required." ValidationGroup="LoginAdmin">*</asp:RequiredFieldValidator>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" colspan="2" style="color:Red;">
                                                    <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td align="center" colspan="2">
                                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login"

                                                        Font-Bold="False" Font-Names="Verdana" Font-Size="Small" Text="Log In"

                                                        ValidationGroup="LoginAdmin" onclick="LoginButton_Click" />
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                            </table>
                        </LayoutTemplate>
                        <LabelStyle Font-Bold="False" />
                    <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
                </asp:Login>


这篇关于LoginStatus文本未正确更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆