Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am designing a login page with some other pages.when the user try to access the other page before login
he should prompt to login page after entereing the login details user should redirected to requested page.login details should be checked against database values .i want to apply form authentication i have tried but page is not redirected.please specify the solution to the problem.




[Edit] Change Subject.-Suresh Suthar[/Edit]
Posted
Updated 18-Aug-11 0:15am
v3
Comments
Mahendra.p25 18-Aug-11 6:00am    
post you code/More information ??
Suresh Suthar 18-Aug-11 6:04am    
Can please explain it or post code.

 
Share this answer
 
Comments
Tejas Vaishnav 19-Aug-11 1:06am    
thanx
Use forms Authentication:
C#
<authentication mode="Forms">
      <forms loginurl="Login.aspx" defaulturl="Default.aspx" path="/" protection="All" timeout="30" />
    </authentication>



Define Authorization in web.config:
HTML
<authorization>
  <deny users="?" />
</authorization>

If you want anonymous user to access particular page then try adding locations,
HTML
<location path="Join.aspx">
  <system.web>
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
</location>
 
Share this answer
 
In web.Config you need to change some values.

C#
<authentication mode="Forms">
      <forms loginurl="Login.aspx" defaulturl="Home.aspx" path="/">
</forms></authentication>
<authorization>
  <deny users="?" />
</authorization>


In Login.aspx.cs Page you need to authenticate the user by cookies

C#
// Your method to auth User

if (IsAuth)
{

// Create the authentication ticket and store the roles in the custom UserData property of the authentication ticket
 FormsAuthenticationTicket authTicket = new
                                FormsAuthenticationTicket(1, // version
                                 txtUserId.Value,           // user name
                                 DateTime.Now,               // creation
                                 DateTime.Now.AddMinutes(1),// Expiration
                                 false,                      // Persistent
                                 userData,                    // User data      
                                 FormsAuthentication.FormsCookiePath);
// Now encrypt the ticket.
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
// Create a cookie and add the encrypted ticket to the 
// cookie as data.
HttpCookie authCookie =
new HttpCookie(FormsAuthentication.FormsCookieName,encryptedTicket);
// Add the cookie to the outgoing cookies collection. 
Response.Cookies.Add(authCookie);
// Redirect the user to the originally requested page
Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUserId.Value, true));

}
 
Share this answer
 
Have a look at some given links to know about Forms Authentication in ASP.NET 2.0
LInk1-MSDN-[How To Implement Forms-Based Authentication in Your ASP.NET Application][^]
Link2-MSDN-[Explained: Forms Authentication in ASP.NET 2.0][^]
or if you have some specific query so please post it.
 
Share this answer
 

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