我在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 =" LoginView1" runat =" 服务器" > < AnonymousTemplate > < span =" 字体家族:Arial;字体大小:10pt;" > 欢迎您,访客 < asp:LoginStatus ID =" LoginStatus1" runat =" 服务器" / > < /span > < /AnonymousTemplate > < LoggedInTemplate > 欢迎, < asp:LoginName ID =" LoginName1" runat =" 服务器" / > < asp:LoginStatus ID =" LoginStatus1" runat =" 服务器" / > < /LoggedInTemplate >
LoggedInTemplate 应包含LoginStatus . 也看看这个. www. developer/net/asp/article.php/3655706/ASPNET-Tip-Using-the-LoginName-and-LoginStatus-Controls.htm [ ^ ]
您好Abhishek, 谢谢回复.我尝试了您的样品,但没有运气.我想这与Login控件有关,就像这样: < asp:Login ID =" LoginAdmin" runat =" 服务器" BackColor =" 白色" BorderColor =" #CCCC99" BorderStyle =" 实心" BorderWidth =" 1像素" EnableTheming =" 真" EnableViewState =" 真实" 字体名称 =" Verdana" 字体大小 =" 10pt" TitleText =" 管理员登录" 字体粗体 =" 错误" 宽度 =" 3 40px" DestinationPageUrl =" 〜/WebPages/Welcome.aspx" onloggedin =" LoginAdmin_LoggedIn" VisibleWhenLoggedIn =" 错误" > < LoginButtonStyle 字体粗体 =" 错误" 字体名称 =" Verdana" 字体大小 =" 小" / > < LayoutTemplate > < 表 边框 =" 0" 单元格填充 =" > 1" 单元格间距 =" 0" 样式 =" border-collapse:collapse;" > < tr > < td > < 表 边框 =" 0" cellpadding =" > 0" 样式 =" 宽度:530px;" > < tr > < td 对齐 =" center" colspan =" 2" 样式 = " 颜色:白色;背景色:#6B696B;字体粗细:粗体;" > 管理员登录< /td > < /tr > < tr > < td 对齐 =" 右" 样式 =" 字体粗细:normal;" class =" style1" > < asp:Label ID =" UserNameLabel" runat =" 服务器" AssociatedControlID =" 用户名" > 用户 名称:< /asp:Label > < /td > < td 对齐 =" 左" > < asp:TextBox ID =" UserName" runat =" 服务器" 宽度 =" 170像素" > < /asp:TextBox > < asp:RequiredFieldValidator ID =" UserNameRequired" runat =" 服务器" ControlToValidate =" UserName" ErrorMessage =" 需要用户名." ToolTip =" 用户名是必需的." ValidationGroup =" LoginAdmin" > * < /asp:RequiredFieldValidator > < /td > < /tr > < tr > < td 对齐 =" 右" 样式 =" 字体粗细:normal;" class =" style1" > < asp:Label ID =" PasswordLabel" runat =" 服务器" AssociatedControlID =" 密码" > 密码:">< /asp:标签 > < /td > < td 对齐 =" 左" > < asp:TextBox ID =" 密码" runat =" 服务器" TextMode =" 密码" 宽度 =" 170px" > < /asp:TextBox > < asp:RequiredFieldValidator ID =" 需要密码" runat =" 服务器" ControlToValidate =" 密码" ErrorMessage =" 需要密码." ToolTip =" 密码是必需的." ValidationGroup =" LoginAdmin" > * < /asp:RequiredFieldValidator > < /td > < /tr > < tr > < td 对齐 =" center" colspan =" 2" 样式 =" 颜色:红色;" > < asp:Literal ID =" FailureText" runat =" 服务器" EnableViewState =" 错误" > < /asp:文字 > < /td > < /tr > < tr > < td 对齐 =" center" colspan =" > 2" > < asp:Button ID =" LoginButton" runat =" 服务器" CommandName =" 登录" 字体粗体 =" False" 字体名称 =" Verdana" 字体大小 =" 小" 文本 =" 登录" ValidationGroup =" LoginAdmin" onclick =" LoginButton_Click" / > < /td > < /tr > < /table > < /td > < /tr > < /table > < /LayoutTemplate > < LabelStyle 字体粗体 =" 错误" / > < TitleTextStyle BackColor =" #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. www.developer/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文本未正确更新
发布评论