Ysgrifennodd sravan_reddy001:
thank u...
i' familiar with ADO.NET but new to the ASP.NET
i hav created some simple applications in C# and VB using ADO.NET.
i think i han handle that database access. what i need is how to
redirect the user to login page if he is not authenticated.
(and if possible he should be able to view the Home page even though
he is not authenticated)
user authentication is the only topic where i got stuck in ASP.NET
Hmm. ADO.NET didn't exist until ASP.NET arrived. If you're thinking of
the old 'classic' ADO, then you need to throw all those ideas away and
start again. ADO.NET is not at all like ADO as used before the days of
..NET.
As to how the authentication works, it is all explained in the Word
document and the code, but to give you a start try looking at this from
Global.asax:
<code>
protected void Application_AuthenticateRequest(object sender,
EventArgs e)
{
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (null == authCookie)
{
// There is no authentication cookie
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch
{
// Log exception details (omitted for simplicity)
return;
}
if (null == authTicket)
{
// Cookie failed to decrypt.
return;
}
// When the ticket was created, the user's role was assigned
// to the UserData part of the cookie.
String[] groups = { authTicket.UserData };
// Create an Identity object
GenericIdentity id = new GenericIdentity(authTicket.Name);
// This principal will flow throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, groups);
// Attach the new principal object to the current HttpContext
object
Context.User = principal;
}
</code>
Sections 2.2, 3 and 5 in the Word document explain how this works in
conjunction with the attributes in the code to raise security challenges
that are satisfied (or not) from the information in the GenericPrincipal
that is stored in the current context.
I really don't think I can be much clearer than that
If you don't know how the Attributes work, you need to look them up on
msdn (look for PrincipalPermissionAttribute, for example).
Peter