日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

解决模拟MOSS用户调用WebService打开个人站点进行操作

發布時間:2023/12/20 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 解决模拟MOSS用户调用WebService打开个人站点进行操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

From:http://www.cnblogs.com/BruceLee521/

?

開始以為要構建

WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent();

GenericPrincipal genericPrincipal =new GenericPrincipal(genericIdentity, roles);

然后把HttpContext.Current.User 置成上面構造的。但發現在打開個人站點時出錯。

然后修改個人站點C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SPSPERS\default.aspx

加入

username:<%=HttpContext.Current.User.Identity.Name%>:
authen:<%=HttpContext.Current.User.Identity.AuthenticationType%>
authe:<%=HttpContext.Current.User.GetType().ToString()%>
identity:<%=HttpContext.Current.User.Identity.GetType().ToString()%>

運行發現頁面輸出

helloWORLD:sunsheng: authen:Forms authe:System.Web.Security.RolePrincipal identity:System.Web.Security.FormsIdentity

才知道構造用戶錯誤,應該構造

System.Web.Security.RolePrincipal
System.Web.Security.FormsIdentity

于是寫了類

public class MOSSFBAImpersonate
??? {

??????? //code sample by Ric
??????? //================
??????? //? MOSSFBAImpersonate mossFBAImpersonate = new MOSSFBAImpersonate(ConfigurationManager.AppSettings.Get("RoleProviderName"));
??????? // FBAIP.Impersonate([roleProvidernameFromWebconfig],[impersonatingUserName]);
??????? //? //to do you work here....
??????? //? FBAIP.Revoke();
??????? //================

??????? #region public functions

??????? public MOSSFBAImpersonate(string roleProviderName)
??????? {
??????????? m_rolePrincipal = (IPrincipal)HttpContext.Current.User;
??????????? m_roleProvider = roleProviderName;
??????????? if (null == m_roleProvider)
??????????????? throw (new Exception("MOSSFBAImpersonate::roleProviderName is null!"));
??????? }
??????? public void Impersonate(string userName)
??????? {
??????????? HttpContext.Current.User = this.CreateHttpUser(m_roleProvider, userName);
??????? }
??????? public void Revoke()
??????? {
??????????? if (null != m_rolePrincipal)
??????????????? HttpContext.Current.User = (IPrincipal)m_rolePrincipal;
??????? }
??????? #endregion
??????? #region private region
??????? private object m_rolePrincipal = null;
??????? private string m_roleProvider = null;

??????? private RolePrincipal CreateHttpUser(string roleProviderName, string userName)
??????? {
??????????? GenericIdentity genericIdentity = new GenericIdentity(userName, "Forms");
??????????? return new RolePrincipal(roleProviderName, genericIdentity);
??????? }
??????? #endregion
??? }

來進行模擬用戶

得到個人站點的代碼可以如下:

public SPWeb GetPersonalWeb(string strAccount, string strPersonalSiteHost)
??????? {
??????????? SPWeb myWeb = null;
??????????? SPSite spPersonalSite = null;
??????????? MOSSFBAImpersonate mossFBAImpersonate = new MOSSFBAImpersonate(ConfigurationManager.AppSettings.Get("RoleProviderName"));
??????????? try
??????????? {
??????????????? mossFBAImpersonate.Impersonate(strAccount);
??????????????? spPersonalSite = new SPSite(strPersonalSiteHost);
??????????????? myWeb = spPersonalSite.RootWeb;
??????????????? mossFBAImpersonate.Revoke();
??????????? }
??????????? catch (System.Threading.ThreadAbortException thex)
??????????? {
??????????????? throw thex;
??????????? }
??????????? catch (Exception ex)
??????????? {
??????????????? throw ex;
??????????? }
??????????? finally
??????????? {
?????????????? //myWeb.Dispose(); //which will be disposed by outside caller.
??????????????? spPersonalSite.Dispose();
??????????? }
??????????? return myWeb;
??????? }

轉載于:https://www.cnblogs.com/Jeffer/archive/2009/11/26/1611632.html

總結

以上是生活随笔為你收集整理的解决模拟MOSS用户调用WebService打开个人站点进行操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。