就可以得到當前登錄的用戶ID,由
WhoAmIRequest request = new WhoAmIRequest();
WhoAmIResponse response = (WhoAmIResponse)Service.Execute(request);
if (response != null)
return response.UserId;
您可以創建這樣一個默認的服務:
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
//This URL needs to be updated to match the servername and Organization for the environment.
Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;
//OrganizationServiceProxy serviceProxy;
OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null)
IOrganizationService service = (IOrganizationService)serviceProxy;
嗨安德里,這是偉大的!但我需要抓住這個用戶ID並在global.asax代碼中使用它。但是由於客戶端腳本在服務器腳本之後運行,我不認爲這個解決方案可以工作。 除非我能找到一種方法來從global.asax文件中獲取用戶ID –