I'm having a problem setting my Session back to Login. Here is my code:
`LabelUser.Text = "";
if (Session["username"] != null)
{
LabelUser.Text = "Welcome " + (String)Session["username"] + "!" + "<a href=/Account/Login.aspx>[Log out]开发者_如何学运维</a>";
}
else
{
LabelUser.Text = "<a href=/Account/Login.aspx>[Log in]</a>";
} `
Now in my login.aspx.cs file i have the session configured, so it checks on admin or user and redirects and fills the session with the username. My problem is that when i debug it works perfect, it shows [Login] and when clicked it redirects me to the login page. I can also login without a problem and it redirects me to well admin or user pages and it changes the label to Welcome Username ! [Logout]. But when i click log out than i do log out but the label doesn't change. Any tips? I don't know if it works with parameters in this case. For example:
`LabelUser.Text = "Welcome " + (String)Session["username"] + "!" + "<a href=/Account/Login.aspx?logoff=j>[Log out]</a>";
`
If it works like this, could i get any help on how to work with this paremeter? Thank you in advance. Mati.
Change in the code as follows login.aspx?val=logout
if (Session["username"] != null)
{
LabelUser.Text = "Welcome " + (String)Session["username"] + "!" + "<a href='/Account/Login.aspx?val=logout'>[Log out]</a>";
}
else
{
LabelUser.Text = "<a href=/Account/Login.aspx>[Log in]</a>";
}
Then on pageload event in login page code for this.
if(Request["val"] == "logout")
{
Session["username"] = null;
}
and also set the credentials as per your requirement
But Mind well this is not the correct method to code for logout.
I don't see ' or " around link try
<a href='/Account/Login.aspx?logoff=j'>
not
<a href=/Account/Login.aspx?logoff=j>
精彩评论