ASP.NET文件上传 - 验证 [英] ASP.NET File upload - Validation

查看:109
本文介绍了ASP.NET文件上传 - 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的应用中,我们使用asp.net FileUpload控件上传文件。

In our application , we are using asp.net FileUpload control to upload files.

要求是,用户应该能够只上传名为.doc,.xls的,.PDF文件。

Requirement is , user should be able to upload only ".doc, .xls , .pdf" files.

系统不应该让他上传其他文件。为了实现这一目标,我们正在验证上传文件的扩展名。如果无效,则抛出错误信息..这工作得很好。

System should not allow him to upload other files. To achieve this we are validating the extension of the uploaded file. If it is not valid then throwing error message.. this works fine..

但是,如果我改变任何EXE文件为.doc文件,则系统允许上传。这不应该发生。

But if i change the any exe file as .doc file , then system is allowing to upload. this should not happen.

有什么办法来验证文件,其内容,而不是它的扩展..?

Is there any way to validate the file with its content instead of its extension ..?

推荐答案

看看这个问题/上<一个答案href=\"http://stackoverflow.com/questions/481743/how-can-i-determine-a-files-true-extension-type-programatically\">stackoverflow.我相信这是一个重复的问题。

Check out this question/answer on stackoverflow. I belive this is a duplicate question.

此外,考虑读取文件的幻数的,特别是如果你只是试图确定是否该文件是一个几可接受类型之一。 幻数维基百科

Also, look into reading a file's magic number especially if you are just trying to determine if the file is one of a few acceptable types. Magic number Wikipedia

这篇关于ASP.NET文件上传 - 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆