簡體   English   中英

無法在已發布的網站中查看本地驅動器文件

[英]Unable to view Local Drive Files in published Website

我想查看計算機本地驅動器中的文件。 該解決方案可以在我的本地計算機上使用,但是當我發布網站時它不起作用。我已成功列出文件,但是當我嘗試下載文件時。 它給出了錯誤。 它在我的本地PC上運行完美,但是當我在IIS上發布它並嘗試查看文件時,它給出了錯誤。

    Response.ContentType = "text/plain";
    Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
    Response.TransmitFile(Server.MapPath(Path.Combine("~/E:/NewFolder/", fileName)));
    Response.End();

錯誤:

The given path's format is not supported. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NotSupportedException: The given path's format is not supported.

Source Error: 


Line 28:         Response.ContentType = "text/plain";
Line 29:         Response.AddHeader("Content-Disposition", "inline;filename=" + fileName);
Line 30:         Response.TransmitFile(Server.MapPath(Path.Combine("~/E:/NewC/", fileName)));
Line 31:         Response.End();
Line 32:         }


Source File: E:\New folder\ViewFiles\ViewFiles\Default2.aspx.cs    Line: 30 

Stack Trace: 


[NotSupportedException: The given path's format is not supported.]
   System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath) +12651960
   System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath) +165
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +112
   System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList) +38
   System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) +92
   System.Web.HttpRequest.MapPath(VirtualPath virtualPath, VirtualPath baseVirtualDir, Boolean allowCrossAppMapping) +549
   System.Web.HttpServerUtility.MapPath(String path) +234
   ViewFiles.Default2.Page_Load(Object sender, EventArgs e) in E:\New folder\ViewFiles\ViewFiles\Default2.aspx.cs:30
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.UI.Control.LoadRecursive() +71
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064

您需要在Server.MapPath中提供文件的物理路徑,而必須提供虛擬路徑。 這就是MSDN關於Server.MapPath的說法,它指定要映射到物理直接目錄的相對或虛擬路徑

如果路徑在托管網站外部,則可以在您擁有的網站內部建立包含要傳輸文件的文件夾的虛擬目錄。

暫無
暫無

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

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