I\'ve built a custom login system for my asp.net mvc 1.0 web application as I store large amounts of user data for each user (I decided against trying to add custom tables f
Here's how we've done it for a hybrid forms/windows authentication app:-
public class MyBaseController
{
protected override void OnAuthorization( AuthorizationContext authContext )
{
if
(
!User.Identity.IsAuthenticated &&
Request.LogonUserIdentity != null &&
Request.LogonUserIdentity.IsAuthenticated
)
{
String logonUserIdentity = Request.LogonUserIdentity.Name;
if ( !String.IsNullOrEmpty(logonUserIdentity) )
{
User loginUser =
Context.Users.FirstOrDefault(
x => x.UserIdentity == logonUserIdentity);
if ( loginUser != null )
FormsAuthentication.SetAuthCookie(
loginUser.LoginName,createPersistentCookie);
}
}
There's some encapsulation that I've taken out for the sake of compactness.