Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
suppose the user is opening the course page to see course info i want to chck that if the user is login then user can access page else it goes to loginpage through " Response.Redirect("Login.aspx");" first login then revert to the page from where it goes to login page by using this
Response.Redirect(Request.Cookies["path"].Value.ToString());

but it is not working it is giving the error that
Object reference not set to an instance of an object.

Tell me some other way to do this or pick out the error plz
Posted
Comments
Prasad Khandekar 25-Apr-13 11:22am    
From course page if use is not logged in then redirect user to login page with query string parameter say returnUrl=course page. In the login process after successful login grab this query string parameter and redirect user to that page.
laiza ramal 25-Apr-13 11:57am    
I am using these codes can you help me with this
course.aspx.cs
if (Request.Cookies["username"] != null)
{

}
else
{
Response.Cookies["path"].Value = Request.Url.AbsolutePath.ToString();
Response.Redirect("login_page.aspx");
}
login_page.aspx.cs

Session["username"] = txtusername.Text;
Response.Cookies["username"].Value = txtusername.Text;
Response.Redirect(Request.Cookies["path"].Value.ToString());

1 solution

If you do this the proper way - using Membership - then all of that is automatic and happens behind the scenes. If the user tries to open a page without logging in, he is auto redirected to the login page, then back where he wanted to g when he logs in successfully.

It's easy to do: MSDN Introduction to Membership[^] will walk you though the whole process.
 
Share this answer
 
Comments
Espen Harlinn 25-Apr-13 11:23am    
You're right, and there is no need to reinvent the wheel ...
laiza ramal 25-Apr-13 12:00pm    
I am using these codes can you help me with this
course.aspx.cs
if (Request.Cookies["username"] != null)
{

}
else
{
Response.Cookies["path"].Value = Request.Url.AbsolutePath.ToString();
Response.Redirect("login_page.aspx");
}
login_page.aspx.cs

Session["username"] = txtusername.Text;
Response.Cookies["username"].Value = txtusername.Text;
Response.Redirect(Request.Cookies["path"].Value.ToString());

i dont know how to revert to original page using membership
OriginalGriff 25-Apr-13 12:03pm    
Read the MSDN link I posted!
laiza ramal 25-Apr-13 11:56am    
My project has many folders each folder has its own config file should i add membership to all files
can i revert to original page after login using membership ?
OriginalGriff 25-Apr-13 12:03pm    
If you use membership, you set the access level by folder - so a login required folder has a stub web.config which affects it and all it's sub-folders. The stub contains only the stuff needed for membership control, so your main web.config is not duplicated.

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