I am applying file upload size restriction, that user can’t upload files more than 30 MB, and give him message if he exceeds the limit.
I am using following code.
if (fileUpload.HasFile)
{
if (fileUpload.PostedFile.ContentLength < 30 * 1024 * 1024) // 30 MB
{
if (fileUpload.FileName != null && fileUpload.FileName != "")
{
UploadFile(fileUpload, "flv,mp3", out videoFileName, out uploadError);
if (uploadError != "")
{
lblMessage.Visible = true;
lblMessage.Text = uploadError;
return false;
}
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "File size exceeds the Limits. Please try uploading smaller size file.";
return false;
}
}
This code works fine in Visual Studio, but when I deploy the application on iis, it doesn’t give me any message if I give more then 30 MB file, and directly upload the file.
where I am doing wrong.
Regards,
Kash
Have you used the standard maxRequestLength config property? It may well be that it’s not suitable for your needs but it will work better in not utilising resources one the file limit is reached.
For an explanantion about how to handle the error see A better way of handling maxRequestLength exceptions