我有一個WCF數據服務,我試圖在DataServiceContext客戶端上使用UpdateObject方法。當我調用SaveChanges方法,我碰到下面的錯誤頁面:WCF數據服務更新返回401-未經授權:由於無效憑據而導致訪問被拒絕
未經授權:訪問被拒絕由於憑據無效
您沒有權限使用的憑據查看該目錄或網頁,你提供。
有沒有人有任何想法,我怎麼能解決這個問題?我發現this,這在理論上可以解決問題,但設置此磁盤訪問對於生產服務來說不是一個現實的解決方案。請記住,在本地機器上運行此WCF數據服務時,它工作得很好。我的電話C#代碼如下:
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
var userName = (string) context[ "UserName" ];
var isAuthenticated = (bool) context[ "IsAuthenticated" ];
if (userName != null && userName.Length >= 1 && collection.Count >= 1)
{
var allNames = string.Empty;
var allValues = string.Empty;
byte[] buf = null;
PrepareDataForSaving(ref allNames, ref allValues, ref buf, true, collection, isAuthenticated);
if (allNames.Length != 0)
{
var client = GetDataContext();
var profile = client.ProfileViews.Where(p => p.UserName == userName).FirstOrDefault();
if (profile == null)
{
profile = new ProfileView() { UserName = userName };
client.AddToProfileViews(profile);
}
profile.PropertyNames = allNames;
profile.PropertyValuesString = allValues;
profile.PropertyValuesBinary = buf;
profile.LastUpdateDate = DateTime.UtcNow;
client.UpdateObject(profile);
client.SaveChanges();
}
}
}
只是一個注意事項 - 確保你點擊「位置」並檢查機器名稱。如果你沒有,它不會找到IIS APPPOOL \'AppPoolName'用戶。我花了一段時間弄清楚這一點:D。謝謝! – dferraro 2013-09-23 16:17:50