我們在特殊的Sharepoint頁面中託管了一個ascx自定義控件(不是Web部件)。此頁面允許用戶將文件上傳到我們的服務器。不幸的是,許可問題阻止Sharepoint將文件保存到網絡位置。在Sharepoint中託管的ASP.NET ascx控件在嘗試保存文件時獲取System.UnauthorizedAccessException
歸因於基於Sharepoint 2007的網站的應用程序池的網絡帳戶具有授予該位置的「修改」和「讀取」訪問權限。
我們使用應用程序池帳戶使用的憑據登錄到其他計算機,並且可以在指定的網絡位置沒有任何問題地創建目錄和文件。
是否有可能Sharepoint試圖使用其他帳戶來保存這些文件,而不是IIS7中的應用程序池設置?
我們得到的錯誤:
消息:訪問路徑 '\蛋白石\ GWL \的圖片\ L36' 被拒絕。
堆棧跟蹤:在System.IO .__ Error.WinIOError(的Int32的errorCode,字符串maybeFullPath)在System.IO.Directory.InternalCreateDirectory(字符串FULLPATH,字符串路徑,DirectorySecurity dirSecurity)在System.IO.Directory.CreateDirectory (字符串路徑,directorySecurity directorySecurity)在ECan.SharePoint.Web.Applications.MyECan_WaterMeterFormDatalogger.SavePhotos()
異常類型: System.UnauthorizedAccessException的
用戶:系統帳號
在文件後面的ascx代碼SavePhotos函數的代碼:
protected void SavePhotos()
{
string wellNo = WellNo.Value;
string epoWaterMeterID = EPO_WaterMeterID.Value;
string dirRoot = ConfigurationManager.AppSettings["PhotoDir"];
string map = wellNo.Substring(0, wellNo.IndexOf('/'));
int photoSaveCount = 1;
foreach (string filePath in Request.Files)
{
HttpPostedFile file = (HttpPostedFile)Request.Files[filePath];
if (file.InputStream.Length > 0)
{
try
{
// Create dir if does not exist
string dir = dirRoot + map;
if (!Directory.Exists(dir)) Directory.CreateDirectory(dir);
// Save file
file.SaveAs(dir + @"\" + wellNo.Replace('/', '_') + "-" + epoWaterMeterID.ToString() + "-" + photoSaveCount.ToString() + ".jpg");
photoSaveCount++;
}
catch (Exception ex)
{
Logger.Write(ex);
}
}
}
}
任何人有任何想法什麼問題可能是什麼?
我已經應用了代碼更改,但仍然遇到同樣的問題。感謝您的想法,但將其松鼠,以備將來參考!對測試框的進一步調查似乎指向IIS上應用程序池使用的帳戶,因爲測試帳戶沒有問題。 – Gavin
事實證明,它是上下文Sharepoint正在保存文件。剛開始時沒有捕捉到它,因爲測試環境應該完全反映現場環境。在測試Sharepoint服務器上,該文件正在使用運行IIS應用程序池的相同帳戶進行保存,但在正在使用IUSR的活動框中保存。 – Gavin