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 ACHUTHA181 reputationPosted Oct 8, 2012, 3:43 AM EDT
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
priya p13 reputationPosted Oct 8, 2012, 5:50 AM EDT
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 ACHUTHA181 reputationPosted Oct 8, 2012, 5:54 AM EDT
if it possible can you share your code..!
priya p13 reputationPosted Oct 8, 2012, 8:31 PM EDT
priya p13 reputationPosted Oct 8, 2012, 9:16 PM EDT
R ACHUTHA181 reputationPosted Oct 9, 2012, 1:21 AM EDT