这是我的代码:

  public ActionResult PostFile(HttpPostedFileBase file, int NoteId)
        {
            FileInfo f = new FileInfo(file.FileName);
            string fullname = f.FullName; //fullname changes depending on if I am using IE or Chrome
        }


这是我的视图(PostFile.cshtml):

@model RiPSShared.Models.RiPSModels.AgencyNote
<form action="@Url.Action("PostFile", "AgencyNotes", new { NoteId=Model.aut_id})" method = "post" enctype="multipart/form-data">
    <label for="file1"> File name:</label>
    <input type="file" name="file" id="file1" />
    <input type="submit" value="Submit" />
</form>


为什么我得到file参数的其他路径?当我使用IE时,正确的路径是("C:\\Users\\User\\Desktop\\sds - Copy (5).docx"),但是当使用Chrome时,我得到的路径是错误的:C:\Program Files (x86)\IIS Express\
我正在使用变量全名来获取路径值...

最佳答案

IE显然发布了整个原始路径,这是一个安全披露问题。幸运的是,Chrome浏览器没有,因此您只收到纯文件名,然后在IISExpress进程的运行上下文中通过调用new FileInfo(file.FileName).FullName进行扩展。

关于c# - 使用Chrome或Internet Explorer时获得不同的路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40363878/

10-12 12:44
查看更多