i am buiding a website in which ia have login page and another is default page
the first step is when ever the admin login than it should be redircted to default page
and if directly open the default page when admin not logged in than it should redirect to login page
and it should work online server not in localhost
please i really need help
Loading
sandeep ramPosted Oct 30, 2009, 1:02 AM
Lets say I have two pages :
1. Login.aspx which is the page through which each and every user has to login
2. Default.aspx which the page to which the user will be redirected to after login.
First up,
Using Forms Authentication,in the web.config, you must set the
defaultUrl=Default.aspx and LoginUrl=Login.aspx
Add the following within configuration tags :
This will ensure that only people who are in the Administrator role can access the default.aspx page. IF they try to open that page directly, then they will be asked to login again.
If you are not using Roles, then replace roles by user in the above code.
Nilanka DharmadasaPosted Oct 29, 2009, 4:35 AM
In login.aspx you can write the code to login and once the user log in successfully you can set his user name to a session variable.
Session["Username"]=.......;
Response.Redirect("default.aspx");
Then in page load event of default.aspx,
protected void Page_Load(object sender, System.EventArgs e)
{
if(Session["Username"] == null)
Response.Redirect("login.aspx");
}
Is this what you wanted to know?? Otherwise pls let me know.