I'm new in asp.net webform. I am trying to create a Login Session. I have my Login.aspx with a button. In the action of this button I execute the login:
if(username.Text == "" || password.Text == "")
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "$(function() { requiredLoginFields(); });", true);
}
else
{
var query = from u in db.Users
where u.Username == username.Text &&
u.Password == password.Text
select u;
if(query.Count() > 0){
Session["Logged"]="Yes";
Session["User"]=username.Text;
Server.Transfer("Home.aspx", true);
}
else
// Working on it
}
On every other page I verify the session in the Page_Load:
protected void Page_Load(object sender, EventArgs e)
{
if(Session == null)
{
Response.Redirect("Login.aspx";)
}
}
My questions. Is it the correct way to implement a login session? Do I need to check the session in every Page_Load of all my webforms?
Is there a way to load automatically my Home.aspx? I mean when I run the project I would like to open http://localhost:64716/ and it load my Home.aspx.
Thank you