我在visual studio 2012中做了一个应用程序 [英] I am doing an application in visual studio 2012

查看:70
本文介绍了我在visual studio 2012中做了一个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用visual studio 2012和sql server作为beckend的应用程序。在一个页面中,我必须通过asp.net中的文件上传控件上传文件。有效的文件类型是.txt,.doc,.jpg,.pdf。应用程序不应采用任何可执行文件(.exe)。通常通过扩展检查我们可以阻止.exe文件上传。但是,通过重命名具有有效扩展名的文件,任何人都可以通过其他方式上传.exe文件。我们必须阻止那些按类型的文件是可执行文件。我怎样才能做到这一点?请从这里帮助我。这太紧急了。

I am doing an application in visual studio 2012 and sql server as beckend. In one page I have to upload a file through file upload control in asp.net. The valid file types are .txt,.doc,.jpg,.pdf. The application should not take any executable file (.exe). Normally by extension checking we can block .exe file upload. But there is another possibilities by which anyone can upload .exe file by renaming the file with valid extension. We have to block those files which are by type is executable file. How can I do that? Please help me out from here. It is too urgent.

推荐答案

如何确定文件是否可执行? [ ^ ]

如何查找文件是否为exe? [ ^ ]

检查文件是否是可执行文件。 [ ^ ]
How to determine if a file is executable?[^]
How to find if a file is an exe?[^]
Check if a file is an executable.[^]


尝试这个选项对我有用...

Try this option it worked for me...
public bool IsFileUploadExecutable(string strfilePath)
{
    var twoBytes = new byte[2];
    using(var stream = File.Open(strfilePath, FileMode.Open))
    {
        stream.Read(twoBytes, 0, 2);
    }
    return Encoding.UTF8.GetString(twoBytes) == "MZ";
}


http://stackoverflow.com/questions/58510/using- net-how-you-you-the-mime-type-of-a-file-on-the-file-signature [ ^ ]


这篇关于我在visual studio 2012中做了一个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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