仅允许文件上载中的.txt本机文件c# [英] Allow only .txt native files in file upload c#

查看:87
本文介绍了仅允许文件上载中的.txt本机文件c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的文件上传控件中,我只能上传txt文件扩展名。假设用户将文件类型从.exe更改为.txt并尝试上传我不应该允许上传它。因为安全原因。所以.txt应该是原生的。它不应该从其他格式更改为.txt。如何在c#中实现这一点?



请帮助我。

Hi,

In my file upload control I can able to upload only txt file extension. Suppose if user change the file type from .exe to .txt and trying to upload I should not allow to upload it. Because of security reason. So .txt should be native. It should not be changed from other format to .txt. How to acheive this in c#?

Please help me.

推荐答案

你无法阻止上传发生。用户将能够上传他们想要的任何内容。服务器端标识.EXE文件。无法可靠地确定文件是否为本机文本,但您可以在文件的前几个字节中查找.EXE文件的签名。它们都以MZ开头。
You can''t prevent the upload from happening. The user will be able to upload anything they want. The identification of an .EXE file comes on the server-side. There is no way to reliably determine if a file is native text, but you can look for the signature of an .EXE file in the first few bytes of the file. They all start with with "MZ".


这篇关于仅允许文件上载中的.txt本机文件c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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