I am working on ASP.NET webforms. I want to redirect the user to login page if user directly enters the URL of any other page. I have added the below code in web.config file and it redirects the user to login page in case the user tries to access any other page directly but there is an issue that when user logs in, it should redirect the user to welcome.aspx page but it redirects to login page again. where is the issue?
code in web.config file i used....
<authentication mode="Forms">
<forms name=".COOKIE" loginUrl="login.aspx" protection="All" path="/" timeout="480"/>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
and login.aspx page code is as:
foreach (var user in db.usertables)
if (user.username == TextBox1.Text && user.password == TextBox2.Text)
{
{
Response.Redirect("welcome.aspx");
}
}
else
{
Label1.Visible = true;
}
Remove the following code from web.config
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
In your aspx.cs page,add the following code
if(authenticated)
{
FormsAuthentication.SetAuthCookie(username,false);
Response.Redirect("welcome.aspx");
}