簡體   English   中英

IIS站點無法訪問本地客戶端驅動器

[英]IIS site cannot access local client drive

我正在做一個項目,允許用戶將文件上傳/下載到SQL流。

這在本地測試時效果很好,但是當我上載它並具有IIS時,它似乎無法正常工作。 我認為這是一個權限問題。

我無法解決。

我什至嘗試使用未投影的文件夾,如下所示(沒有運氣):

string tempPath = System.IO.Path.GetTempPath();
string tempPath2 = System.Environment.GetEnvironmentVariable("TEMP");
string tempPath3 = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
var fullpath = Path.Combine(tempPath2, "MeDoc.Doc");

我什至嘗試使用身份驗證,如下所示(也沒有運氣):

DirectoryInfo di = new DirectoryInfo(fullpath);
DirectorySecurity acl = di.GetAccessControl();
AuthorizationRuleCollection rules = acl.GetAccessRules(true, true, typeof(NTAccount));
WindowsIdentity currentUser = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(currentUser);

DirectorySecurity fsecurity = Directory.GetAccessControl("C:\\Temp\\Docs\\");
SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);
FileSystemAccessRule writerule = new FileSystemAccessRule(sid, FileSystemRights.Write, AccessControlType.Allow);

fsecurity.AddAccessRule(writerule);
// Set the ACL back to the file
Directory.SetAccessControl("C:\\Windows\\Temp\\", fsecurity);

if (!string.IsNullOrEmpty("C:\\Temp\\Docs\\") && Directory.Exists("C:\\Temp\\Docs\\"))
{
    // Get your file's ACL
    DirectorySecurity fsecurity3 = Directory.GetAccessControl("C:\\Temp\\Docs\\");

    // Add the new rule to the ACL`enter code here`
    fsecurity3.AddAccessRule(writerule);

    // Set the ACL back to the file
    Directory.SetAccessControl("C:\\Temp\\Docs\\", fsecurity);
}

即使在web.config中:

<authorization>
<allow users="?"/>
<!--<anonymousAuthentication enabled="true" />-->
</authorization>

IIS服務正在使用網絡帳戶。

任何幫助表示贊賞。

請注意,在機器上調試時,我使用的幾乎所有方法都能完美工作。

當它在運行網絡帳戶的Web服務器上的IIS上時,情況就不同了。

在IIS中,它使用的池使用網絡服務(是的,我也嘗試了運氣不好的本地系統)。 至於網站許可,我允許讀寫。

如果有人可以提供幫助,甚至可以做一個更好的示例項目,我將不勝感激。

實際上,我之前已經回答過同樣的問題...

https://stackoverflow.com/a/16948507/1246574

這是從該帖子復制的步驟。

將文件夾的權限授予應用程序池。 您將瀏覽到Windows中的文件夾並編輯權限,並以用戶身份添加IIS APPPOOL \\ appPoolNameHere,然后為其提供所需的任何權限。

分步說明...

-打開Windows資源管理器

-瀏覽到您的文件夾

-右鍵單擊該文件夾,然后轉到“屬性”

-在“安全性”選項卡上,單擊“編輯”

-點擊添加

-在“位置”下,確保它指向您的本地計算機,而不是域

-對於對象名稱,在下面輸入,但將MyAppPool替換為應用程序池的名稱...

IIS APPPOOL \\ MyAppPool

-將權限設置為“完全”,或僅添加“寫”或任何您需要的權限。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM