Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends

I want to redirect the user to the Login page when he is not logged in.
After entering the details and logging in he should be redirected to the same page from where he was redirected.

Thanks in advance
Posted
Updated 24-Apr-12 21:56pm
v2

Hi,
If you config your application and set the authentication mode to Forms, then when a user logs in he/she will be redirected automatically to the requested page. Take a look at this page:
http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx[^]

I hope it helps,
Cheers
 
Share this answer
 
Very simple code in Asp.net and MVC
Asp.net
public void Login(string userName,string pwd){
    if(userName == "XXXX"  && pwd == "XXX") // or DB query
    {
        response.redirect("%youpage%");
    }
    else
   {
       response.redirect("%login.aspx%");
   }
}

if you use MVC
public ActionResult loginAction(string userName,string pwd)
{
   //same logic
}


and you can configure in your web.xml or Global.ascx
 
Share this answer
 
v2
Hi,

If you are using Login control then you need not do any thing. The default behavior of the Login control is to return the user to the referring page. You can set DestinationPageUrl property of Login control to redirect a user to a specific url.
 
Share this answer
 
Comments
RashdSiddique 25-Apr-12 3:55am    
Thnaks but i am not using Windows Login Control
Deepak_Sharma_ 25-Apr-12 4:23am    
There is no Windows Login Control, above solution is about using ASP.NET Login control
RashdSiddique 25-Apr-12 4:43am    
I mean Login control which Microsoft has provided by default

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