在用户登录后,登录按钮仍然保持登录状态,并且没有显示用户名并且未启用注销但是在用户名和密码为...之后它将我指向主页 [英] after user s logged in the Login button still stays Login and no username is displayed and logout is not enabled but it Directs me to the home page after the username and the password are...

查看:56
本文介绍了在用户登录后,登录按钮仍然保持登录状态,并且没有显示用户名并且未启用注销但是在用户名和密码为...之后它将我指向主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录页面的代码

PLZ帮我显示登录用户名并启用登出链接



简单登录页面



my code for the login page
PLZ help me to display the login user name and also enable the logout link

Simple Login page

    <html xmlns="http://www.w3.org/1999/xhtml">
<br />
<head>
 <h2>
        Log In
    </h2>
    <p>
        Please enter your username and password.
        <asp:HyperLink ID="RegisterHyperLink" runat="server" EnableViewState="False" 

            ForeColor="Blue" NavigateUrl="~/register.aspx">Register if you don't have an account.
    </p>
<div class="accountInfo">
                <fieldset class="login">
                    <legend>Account Information</legend>
<title>Login Form</title>
</head>
<body>
<div>
<table>
<tr>
<td>
Username:
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"/>
<asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" runat="server" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<asp:TextBox ID="txtPWD" runat="server" TextMode="Password"/>
<asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD" ErrorMessage="Please enter Password"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</td>
</tr>
</table>
</div>
</body>
</fieldset></div>
</html>



网站母版页


site master page

<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="True">
    <anonymoustemplate>
        [ <a href="~/Lg1.aspx" ID="HeadLoginStatus"  runat="server">Member Log In ]
    </anonymoustemplate>
    <loggedintemplate>
        <asp:LoginName ID="LoginName1" FormatString="Welcome {0}!" runat="server" />
        [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
    </loggedintemplate>





CS文件



CS file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Lg1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("select * from User_information where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("Default.aspx");
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}
    }

推荐答案

您的浏览器会抓住该页面,以便您可以执行此操作。 。



1 :: Response.Cache.SetCacheability(HttpCacheability.NoCache); ''把这一行放在所有页面加载事件''



2 ::你必须在登录后重新加载页面和logut



尝试这可能对你有用
your browser catch the page so you can do this . .

1:: Response.Cache.SetCacheability(HttpCacheability.NoCache); ''put this line in all page load event''

2 :: you have to reload page after login and logut

try this may work for you


这篇关于在用户登录后,登录按钮仍然保持登录状态,并且没有显示用户名并且未启用注销但是在用户名和密码为...之后它将我指向主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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