Does PostedFile.FileName work differently in .Net

2019-05-15 06:28发布

I'm working on an ASP.Net site which allows users to link documents using a UNC path. This site is used by a customer of ours for internal processes, so all users on their domain should have access to the UNC path.

When a user wants to add a linked document, they select the file using a FileUpload control. Previously in .Net 2.0, the control's PostedFile.FileName property returned the filename and the full UNC path. Now we are using .Net 4.0 and it only returns the filename.

Here's my main question: Does PostedFile.FileName work differently in .Net 4.0 compared to 2.0?

If not, what else could cause this problem?

1条回答
在下西门庆
2楼-- · 2019-05-15 06:51

I assume that it's not .NET but the internet explorer which growed up in security.

From here:

Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.

So you could

  1. Change the logic in the server-side code - It should not be dependent on the client-side file path location and should simply use the FileName property of the FileUpload control.

  2. Enable the IE 8 / IE 9 option to include the local directory path for the Internet Zone on the client-side(annoy the user).

enter image description here

查看更多
登录 后发表回答