1) code to avoid malicious image being upload in asp.net
- actully i want fileuploader using asp.net which upload valid image only..but my fileuploader uploading invalid image like image with malicious code(i.e with extension .exe)means i have check extension and all in my code...but i want simultanous checking of image content,so that hacker will not able to upload malicious image etc..
Loading
R ACHUTHAPosted Oct 9, 2012, 5:21 AM
priya pPosted Oct 9, 2012, 1:16 AM
priya pPosted Oct 9, 2012, 12:31 AM
R ACHUTHAPosted Oct 8, 2012, 9:54 AM
if it possible can you share your code..!
priya pPosted Oct 8, 2012, 9:50 AM
But my question is that my image is with .jpeg extension but after opening its exceutable file(i.e malicious image).and i don't want to upload excutable image(i.e malicious image) with jpeg extension...
and i allready check extension(jpeg,jpg,png)and all.so my code checking only extension,and after cheking extension it allow for malicious image(with jpeg extension) also.
so plz tell many idea how to solve it
R ACHUTHAPosted Oct 8, 2012, 7:43 AM
try the below code
if (FileUpload1.HasFile)
{
string extension = System.IO.Path.GetExtension(FileUpload1.FileName);
if (extension == ".jpg")
{
FileUpload1.SaveAs("yourpath" + FileUpload1.FileName);
}
else
{
Response.Write("Only .Jpg allowed");
}
}
or
for alowing only image in file control you can use the following RegularExpressionValidator