How to prevent authentecated user to acces login page

Posted by SurajRane under ASP.NET on 7/2/2010 | Views : 1887 | Status : [Member] | Replies : 2
Hi,

I want to prevent authenticated users to access login page.

Once user is authenticated and if he go to login page, he should be redirected to previous page or return url

do reply.




Responses

Posted by: BangaruBabu on: 7/2/2010 [Member] Starter

Up
0
Down
Under Login Page  


SqlDataAdapter da=new SqlDataAdapter("select username,password from logintable where username='"+txtname.text+"'",'"+txtpassword.text+"'",cn);
DataSet ds=new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
FormsAuthentication.RedirectFromLoginPage(txtname.text.Text, );
Response.Redirect("~/Success.aspx");
}
else
{
return;
}

In Web.Config

<authentication mode="Forms">
<forms name="myAuthenticaltion" path="/" loginUrl="login.aspx" protection="All" timeout="30" >
<credentials passwordFormat="Clear" >
</credentials>
</forms>
</authentication>

<authorization>
<deny users="?" />
</authorization>





BangaruBabu Pureti
http://bangarubabupureti.spaces.live.com/

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/2/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Day

What you can do is to check if the session is Null or not, if its not null do do anything else send him to the login page like this


If(Session["Username"] == null)
{

//Send him to the Login page
}
else
{

//do nothing this will keep him on the same page
}


Thank you for posting at Dotnetfunda
[Administrator]

SurajRane, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response