在silverlight c#中确定没有扩展名的文件类型

时间:2013-09-18 12:20:08

标签: c# silverlight silverlight-4.0

开发一个webapp,用户可以将图像上传到服务器。 我想确保用户上传图像,而不是其他任何内容,如反向shell或恶意内容。因此,我无法使用扩展程序,因为您可以轻松伪造它。

 var dlg = new OpenFileDialog();
            //dlg.Filter = "";
            dlg.Multiselect = false;

            bool? openClicked = dlg.ShowDialog();
            if (openClicked == true)
            {
                Stream stream = dlg.File.OpenRead();

                BinaryReader binary = new BinaryReader(stream);

//Determine filetype here.

                byte[] data = binary.ReadBytes((int) stream.Length);

必须有一种简单的方法吗?

Tl;博士:我如何确定文件类型以防止反向shell?

1 个答案:

答案 0 :(得分:0)

您需要应用此类文件过滤器,

     OpenFileDialog dlg = new OpenFileDialog();
     dlg.Filter = "All files (*.*)|*.*|PNG Images (*.png)|*.png";
相关问题