![](/img/trans.png)
[英]How do I call a javascript file that's embedded in a dll in my asp.net web application?
[英]ASP.NET - I am generating an .XLS file with a DLL, how do I grant permissions for writing to file? (IIS 7)
我正在用DLL生成.XLS文件(Excel庫http://code.google.com/p/excellibrary/ )
我已添加此DLL作為對我的項目的引用。
將.XLS保存到磁盤的代碼正在運行,但是遇到權限問題。
我試圖為IUSRS,網絡服務和每個人設置完全訪問權限,只是為了看看我是否可以使它正常工作,而這些似乎都沒有任何作用。
這是我要寫入文件的位置:
c:/temp/test1.xls
這是錯誤:
[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessPermission.Demand() +54
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +2103
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +138
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +89
System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share) +58
ExcelLibrary.Office.CompoundDocumentFormat.CompoundDocument.Create(String file) +88
ExcelLibrary.Office.Excel.Workbook.Save(String file) +73
CHC_Reports.LitAnalysis.CreateSpreadSheet_Click(Object sender, EventArgs e) in C:\Users\brian\Desktop\Enterprise Manager\CHC_Reports\LitAnalysis.aspx.vb:19
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11041511
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11041050
System.Web.UI.Page.ProcessRequest() +91
System.Web.UI.Page.ProcessRequest(HttpContext context) +240
ASP.litanalysis_aspx.ProcessRequest(HttpContext context) +52
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +599
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171
我需要做什么來診斷權限問題並允許文件創建嗎?
謝謝。
我認為這與文件安全性無關,而與.NET代碼訪問安全性有關。 您可以安裝.NET SDK,它將在管理工具中添加類似“ .NET 2.0配置”的內容,您可以在其中進行配置,也可以使用caspol命令行實用程序。 另外,請查看專門針對ASP.NET的本文: http : //msdn.microsoft.com/zh-cn/library/ms998326.aspx
編輯:現在,我看起來更多了,請注意CodeAccessSecurity Engine。 絕對是我的想法。 您可以基於URI,強名等授予或拒絕對.NET應用程序的特定權限。這些權限包括對文件,注冊表等的訪問。
從IIS將文件寫入HDD時,您需要在文件夾上設置“寫入”權限(例如c:\\ temp)。 這是因為某些IO進程先刪除,然后重新創建文件(而不只是更新),並且刪除文件時會破壞權限。 通常,您需要授予對IUSR *,IWAM *和ASPNET的讀/寫權限。
我相信Nelson對於90%遇到此錯誤的人來說是正確的道路...我相信tgolisch對於其余大約8%的人是正確的道路。
但是,為我的應用程序提供服務的應用程序池顯然沒有特定權限來寫入相關文件夾。 因此,我切換了用於服務應用程序的應用程序池,以便在上下文中運行:本地系統。
部署應用程序時,我需要確定應用程序池在哪個身份下運行,並驗證它是否有權訪問適當的文件夾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.