ASP.NET对同一域上3个站点的身份验证

时间:2012-09-25 08:40:07

标签: forms authentication cookies forms-authentication

我需要通过3个站点进行表单身份验证(login.mydomain.com,www.mydomain.com和admin.mydomain.com)。用户来自MSSQL-DB,但我不认为这是一个问题。

我按照此处所述设置了我的web.config:http://msdn.microsoft.com/en-us/library/eb0zx8fc.aspx,但它不起作用。

我的登录代码:

string RoleString = string.Empty;
RoleString = user.Gruppe.Bezeichnung;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Username, DateTime.Now, DateTime.Now.AddMinutes(2), false, user.Gruppe.name, FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
cookie.Name = "UserCookie";
cookie.Domain = ".mydomain.com";
Response.Cookies.Add(cookie);
Response.Redirect("http://www.mydomain.com/Default.aspx");

可能是什么问题?我在webconfig中尝试使用机器密钥,但是这给了我一个MAC的Viewstate错误...

0 个答案:

没有答案