2017-02-06 1 views
0

Я хочу просматривать файлы на локальном диске на компьютере. Решение работало на моем локальном компьютере, но когда я опубликовал сайт, он не работает. Я успешно перечислил файлы, но когда я пытаюсь загрузить файл. он дает ошибку. Он отлично работал на моем локальном компьютере, но когда я опубликовал его в 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 

ответ

0

Вы даете физический путь файла в Server.MapPath, тогда вы должны дать виртуальный путь. Это то, что говорит MSDN о Server.MapPathЗадает относительный или виртуальный путь к карте для физического прямого

Если путь находится вне размещенного сайта вы можете сделать виртуальный каталог папки, содержащими файлы, которые вы хотите передать, внутри вашего сайта.