我的疑惑:
1 主站 www.abc.com
2 子站 1.abc.com 2.abc.com
3 子站 *.abc.com (泛域名解析,格式: 会员名.abc.com, 用来实现类似博客等功能)
情况描述:
我从 会员名1.abc.com 登录后, 在 会员名2.abc.com 也会出来编辑添加的链接
需要实现:
泛域名解析的站点我如何实现各个会员只能修改自己的内容
就是 我从 会员名1.abc.com 登录后, 在 会员名2.abc.com 也不会出来编辑添加的链接
总的说就是实现通行证,一个地方登录,全部站点都能共享这个登录.
但泛域名解析的站需要实现只能编辑自己的内容
贴上现有的登录代码,使用FormsAuthentication
Code
string userData = uObject.J_ID + ";" + uObject.J_UserName;
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, uObject.J_UserName, DateTime.Now, DateTime.Now.AddDays(7), false, userData);
string encryptuObject = FormsAuthentication.Encrypt(ticket);
string url = HttpContext.Current.Request.Url.ToString().ToLower();
string domain = Regex.Match(url, @"//([^/]+)").Groups[1].Value;
int length = domain.Split(new char[] { '.' }).Length;
//如果为www.abc.com的形式,则只截取.abc.com
if (length >= 3)
{
domain = domain.Substring(domain.IndexOf('.'));
}
HttpCookie ck = new HttpCookie(".ASPXAUTH", encryptuObject);
ck.Path = FormsAuthentication.FormsCookiePath;
ck.Expires = DateTime.Now.AddDays(7);
HttpContext.Current.Response.Cookies.Add(ck);
FormsAuthentication.SetAuthCookie(uObject.J_UserName, false);