Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

i am asp.net developer but membership is new for me i hv 60% knowledge of tht.
now the problem is i wanted to protect the page form user without login
ex. i hav made website with

1) login.aspx
2) logout.aspx
3) inbox.aspx

now without login user should not access inbox.aspx page like if user input page url in address bar or hit the page then he should be redirect to login page if user is not logged in.







C#
bool authenticated = User.Identity.IsAuthenticated;;
         string auth = authenticated.ToString();
         if (authenticated == true)
         {
             MembershipUser myObject = Membership.GetUser();
             //above syntax will return logged in current user 
         }
         else
         {
         //redirct to login page
         }

but its not looking safe to me, i wanted to use this concept in big website. plz if any body can suggest.

Please reply in c sharp with asp.net



Posted
Updated 9-Dec-10 19:22pm
v3
Comments
TheyCallMeMrJames 9-Dec-10 22:44pm    
are you using asp.net mvc? all you have to do is put an attribute on the controller class (or method) to protect the views. it's literally 1/2 a line of code. -cheers
desaihardikj@gmail.com 10-Dec-10 1:05am    
no, i am not using mvc? i dnt hv enough idea about mvc. :(

These links might help you
Forms Authentication[^] and here[^]
 
Share this answer
 
Hi,

Try to close the page cache using ...
C#
public static void DisablePage()
{
    //Used for disabling page caching
    HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    HttpContext.Current.Response.Cache.SetValidUntilExpires(false);
    HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    HttpContext.Current.Response.Cache.SetNoStore();
}


call this method in Page_load event and
C#
DisablePage();
        if (Session["isLogged"] == null)
        {
            Response.Redirect("~/Default.aspx");
        }

If you are using Master-Page you can solve your problem.

Regards.
 
Share this answer
 
Comments
senguptaamlan 10-Dec-10 2:54am    
can be easily solved by using Form based authenticating and doing some entries in web.config file....no need of Master page and custom coding...

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