Quote:
Originally Posted by karthi84
hi frinny,
now i get a lot of problem in my page. when i go to other pages whithout logging in using the url, it should be redirected stating please login. but for me that is not working.
similarly when i logoff after loging in this message is displayed. the below shown are the two different page codings. please help me in this,
Login Page:
...
can u help me in solving this problem
Hi Karthi,
I'm not quite sure what you are trying to do with the code you posted.
First of all, aren't you supposed to check the user's credentials before passing them on to the second page?
Secondly, is your lblPlzLgn an error label or the actual text for prompting the user?
You'll have to better explain what exactly is going on.
What happens to your site when the error occurs?
Does it redirect when its not supposed to?
Does it not redirect when it is supposed to?
Looking at your code I don't see any sort of user validation. I'd validate the user on the first page before allowing them to go on the second page.
Eg. I'd set the Session["UnAuthorised"] variable to true if the user's credentials weren't valid and I'd set the variable to "false" if the user's credentials were valid. Then on every page I'd check to see if the Session["UnAuthroised"] variable is null or if it's true...and if so I wouldn't do any processing on that page, but instead redirect the user back to the starting page.
-
private void Page_Load(object sender, System.EventArgs e)
-
{
-
lblPlzLgn.Visible=false;
-
-
if(Session["UnAuthorised"]!=null)
-
{
-
lblPlzLgn.Visible=true;
-
Session["UnAuthorised"]="";
-
}
-
}
-
private void Button1_Click(object sender, System.EventArgs e)
-
{
-
Session["text"]=TextBox1.Text;
-
TextBox1.Text="";
-
TextBox2.Text="";
-
/* You should check to see if the user's credentials are valid
-
here before Redirecting them to the SecondPage.aspx.
-
Here I would do something like:
-
-
if(userCredentialsAreValid()==true)
-
{ //userCredentialsAreValid() is the function
-
//that returns true if the user's credentials are valid and false otherwise.
-
Session["UnAuthorized"]=false;
-
Response.Redirect ("SecondPage.aspx");
-
}
-
else
-
{
-
Session["UnAuthorized"]=true;
-
}
-
*/
-
}
-
-
-
if(Session["UnAuthroised"]==null)
-
{
-
Response.Redirect("Login.aspx");
-
}
-
else if (Session["UnAuthorized"]==true)
-
{
-
Response.Redirect("Login.aspx");
-
}
-
else
-
{
-
if(Session["text"]!=null)
-
{
-
alert();
-
}
-
else
-
{
-
Session["UnAuthorised"]=true;
-
Response.Redirect("Login.aspx");
-
}
-
}
-
I don't know if any of the above suggestions are going to help because I'm not exactly sure what the problem is.
-Frinny