Click here to Skip to main content
15,915,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi!! i am working in asp.net and i want to deny the user login directly home.aspx if user try to access the webste just putting the home.aspx address in url.
Posted
Updated 7-Aug-12 6:53am
v3

The best way is to implement Membership[^] and only expose the registration / login / forgotten password pages in the root folder. You can then protect all the rest of your site with a simple line in web.config
 
Share this answer
 
Comments
bbirajdar 29-Mar-12 6:08am    
Best answer . My 5
Monjurul Habib 30-Mar-12 4:49am    
5!
santosh_k 31-Mar-12 0:07am    
hi!! thanks
If you have not implemented the Membership provider, then the alternative solution will be to create a session variable for logged in users which should be checked in Page_load event of Home page. If its null, then redirect the user to login page.

You can create a BasePage if you want the same functionality in multiple pages and your webpages should derive from this BasePage.
 
Share this answer
 
Comments
santosh_k 30-Mar-12 1:50am    
please provide me the code for creating session variable for the logged users.
bbirajdar 30-Mar-12 5:51am    
Please refer following url,

After successful login add following code to add user data in session.

HttpContext.Current.Session["UserID"] = data.UserId;
HttpContext.Current.Session["Email"] = data.Email;

Add following code in master page.



protected void Page_Load(object sender, EventArgs e)
{

if (Session["UserID"] == null)
{
Response.Redirect("Login.aspx");

}
}
santosh_k 30-Mar-12 9:04am    
i have not taken the master page. i have used login.aspx page and home.aspx page so where i will place these codes.reply me...
santosh_k 31-Mar-12 0:05am    
hi!! thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900