I have got it working using the following simple code, Global.asax adds the Windows user if they have not been to the site before, and Login.aspx allows the user to either click a box to say they want to authenticate as the user logged on or they are free to enter a username and password using the forms Login Wizard.
Authentication (Login.aspx on same page as LoginWizard):
function AuthenticateWindowsUser{
string LoggedOnUserName = Request.ServerVariables["LOGON_USER"].ToString();
if (Membership.FindUsersByName(LoggedOnUserName).Coun t > 0)
{
FormsAuthentication.RedirectFromLoginPage(LoggedOn UserName, false);
}
}
Create User (global.asax):
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
string LoggedOnUser = Request.ServerVariables["LOGON_USER"];
if (Membership.FindUsersByName(LoggedOnUser).Count == 0)
{
string DefaultPassword = "¬áé4óÃgâ¬$*"; //something obscure here
string EmailAddress = "
[email protected]";
MembershipCreateStatus status;
MembershipUser mu = Membership.CreateUser(LoggedOnUser, DefaultPassword, EmailAddress, null, null, true, out status);
if (status != MembershipCreateStatus.Success)
{
throw new ApplicationException(status.ToString());
}
else
{
ProfileCommon pc = (ProfileCommon)ProfileBase.Create(mu.UserName, true);
pc.FirstName = "test";
pc.LastName = "tester";
pc.WindowsUser = true;
pc.Save();
}
}
}
Steve