sharepoint匿名实现的另一种方法

1. 新建一个区域 82

2. 设置MemberShipProvider

 

代码
public override bool ValidateUser(string username, string password)
{
if (username == "guest")
return true;
else
return false;
}

public override MembershipUser GetUser(string username, bool userIsOnline)
{
if (username == "guesT")
return new MembershipUser(this.Name, "Guest", "Guest", string.Empty, string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);
return null;
}

public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
{
totalRecords
= 1;
MembershipUserCollection userCollection
= new MembershipUserCollection();
userCollection.Add(
new MembershipUser(this.Name, "Guest", "Guest", string.Empty, string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue));
return userCollection;
}

public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
if (string.Format("guest").Contains(usernameToMatch))
return GetAllUsers(1, 1, out totalRecords);
else
{
totalRecords
= 0;
return new MembershipUserCollection();
}
}

 

 

 



3. 配置82站点为匿名访问, 设置MemberShipProvider

4. 更改82的global.ashx文件

 

代码
1 <script RunAt='server'>
2 protected void Application_AuthenticateRequest(Object sender, EventArgs e)
3 {
4 string cookieName = FormsAuthentication.FormsCookieName;
5 HttpCookie authCookie = Context.Request.Cookies[cookieName];
6 if (authCookie == null)
7 {
8 FormsAuthentication.SetAuthCookie("guest", false);
9 }
10 }
11  </script>

 

posted @ 2010-09-27 16:16  一只老鼠  阅读(193)  评论(0编辑  收藏  举报