i am trying to test to see if i get an error if i upload more than 3mb file size but instead i get the IE error (see below)
here is the code i have. - what i want is if the user try to upload more than 3mb file size display an error.
if (fUpload.HasFile)
{
// Get the size in bytes of the file to upload.
int fileSize = fUpload.PostedFile.ContentLength;
// Allow only files less than 3145728 bytes (approximately 3 MB) to be uploaded.
if (fileSize > 3145728) //if (fUpload.PostedFile.ContentLength <= 3072)
{
..............
.............
}
else
{
// Notify the user why their file was not uploaded.
this.lblStatus.Text = "Your file was not uploaded because it exceeds the 3 MB size limit.";
}
}
<system.web>
<httpRuntime maxRequestLength="3145728" />
Internet Explorer cannot display the webpage
This problem can be caused by a variety of issues, including:
•Internet connectivity has been lost.
•The website is temporarily unavailable.
•The Domain Name Server (DNS) is not reachable.
•The Domain Name Server (DNS) does not have a listing for the website's domain.
•There might be a typing error in the address.
•If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.
You're doing this on server side. This means the file already has been started to upload to the server. I couldn't find a solution too and I don't know if there is one for this issue.
here is how i fix it:
By Default, you should be able to upload a file upto 4MB and MaxRequestLength is in Kilo Bytes. So, Default value is 4096KB. If you try to upload the file with size over 4MB, you will get an error. So, Increase that to some 25Mb or a large number. Then you should be able to track file size in your code.
<httpRuntime maxRequestLength="2097151" executionTimeout="3600"/>
Related
My requirement is display files and folders without hostname/ip address as header as this can be vulnerable. And existing code working on IIS 7 and new one IIS 10.
I successfully achieved file/folder display by enabling 'Directory browsing' but unsuccessful with 'without hostname/ip address as header'. So looking for help on this configuration part.
The hight lighted text(localhost in this case) must not display
I'm struggling to figure out what exactly is happening. I am using GdPicture to save a scanned document through java script using their COM+ code and source project as my starting ground. Long story short is their function issues a HTTP PUT command specifying the file name to be saved.
When I execute the command I see that the request is getting to my server, and even has the appropriate content size to include the pdf document. I even get a 200 response back to my browser, no errors or anything...... yet the pdf doesn't get saved. Is that because PUT isn't the right way to do this? I don't have the option to POST the file because the transfer is wrapped in GdPicture's api... so with that said.
I have done the following
Ensured that IIS_IUSRS group has write permissions to the "Upload" virtual directory
Added a handler that specifically allows the PUT verb for "*.pdf"
Removed the StaticFileHandler for the "Upload" virtual directory
I aplogize for the links, but I don't have 10 rep points yet
PUT Request from FIDDLER
Response
** Edit **
More information about GdPicture, I have already contacted them and their function is not the problem. The implementation is as simple as
var status = oGdViewer.SaveDocumentToPDF_2("http://domain.com/Annotation/Upload/" + FileName, "user", "pass");
Thanks!
Environment:
-SharePoint 2010 foundation
-Claim based authentication
-Execution time out in web.config is set to 3600
Overview:
We have an excel export functionality where we connect to AD and SQL databases to fetch Users and their related data for a perticular Organization Unit (OU)in Active Directory.
We have on OU in AD which has got around 1400 users in it. We are using Open and Closed xml to generate excel file which works fine and takes about 11-14 minutes to generate a file on the server on following path
C:\inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectyrName\Excel\FileName.xlsx
Immediately after generating a file we have following piece of code which would read file from server and dump it on output steam and presents a file ope-save as dialog box in browser to end user.
Problem Description:
When an Organization has less number of users and it does not take more than 5-6 minteus to generate the file on server, following piece of code successfully downloads the file on browser. But when for above mentioned OU where we have 1400 users the reponse.writefile function fails and in browse we get to see 'Browse can not display this web page' (when fiddler was on we found it gives - http 504 error). Surpricingly if we perform this export from the server itself (i.e browse the web site on server) it downloads without issue.
protected void lnkbtnDownloadFile_Click(object sender, EventArgs e)
{
String fileName = #"C:\inetpub\wwwroot\wss\VirtualDirectories\VirtualDirectyrName\Excel\540KBFileWhichFails.xlsx";
//File size is hardly ~500 KB
//Wait for around 12 minutes, to mimic a scenario of file generation which takes time on staging and prod. environment.
System.Threading.Thread.Sleep(720000);
try
{
if (fileName != "")
{
var file = new FileInfo(fileName);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
Response.Write("This file does not exist.");
}
}
catch (Exception ex)
{
//This would usually give thread aboart exception but thats expected.
}
}
we dont see any error in ULS logs, event logs specific to this behavior.
Please note , response.TransmitFile also gives same behaviour.
any idea ?
What I suspect here is that you have felt on session lock. What I mean is that the download and the generation and all this calls made using the session, and session locks everything until finish.
To solve this issue do two thinks.
When you generate this file, generate it ether with thread ether with handle with out session needed
Download this file from a handler (that not use session) and not from the page post back.
For example you make a handler, eg download.ashx and you make a link to your page as download.ashx?thisfileId=7723423&SecurityID=82jkj1288123 Inside your handler you read this parameters and you send the file. But if you make this on the page then a way is to disable the session for this page if you not use session, for example you set EnableSessionState="false" on the first line declarations.
Some similar questions and session relative answer.
call aspx page to return an image randomly slow
Replacing ASP.Net's session entirely
How to deliver big files in ASP.NET Response?
I figured out the issue, It was an issue with the Idle time out issue in the Hardware load balancer we where using. Default value in load balancer was 0 which meant 11 minutes and my file generation was taking longer than that which caused this issue. Increasing load balancer idle time out issue seems to be solutions.
I have a web service on which the end users will be uploading ZIP archives that can be very large (one test file is over 200MB). I'd like to handle oversized files proactively and size-limited upload failures gracefully.
Since the web app will be deployed on customers' machines, so I cannot easily ensure that the configuration matches any fixed size. I've documented how to use the appcmd command for them to set the requestLimits.maxAllowedContentLength value beyond the 30MB default.
But I'd like to handle it in the web app; I'm hoping for two things:
To show the current limit on the page where they initiate the file upload, something along the lines of:
Each file upload is limited to 15MB. If your archive is larger, (etc., etc., etc.)
To give a meaningful error when that size is exceeded. Currently, it takes a long time for the data to be sent, and then I see a misleading 404 page.
Any thoughts?
[Edit]
http://www.developer.com/db/article.php/10920_3426051_2/Limiting-Upload-Sizes-with-ASPNET.htm
I found the above article -- but while I can intercept the error I keep getting a connection reset in the browser on Request.Redirect() or Context.RewritePath() so it's really no better than the 404. Hmmm, actually that's with VS2008's debug server, not with IIS.
To get the masxAllowed content you can use this
protected int GetMaxUploadSize()
{
System.Web.Configuration.HttpRuntimeSection httpRuntimeSec = (System.Web.Configuration.HttpRuntimeSection)ConfigurationManager.GetSection("system.web/httpRuntime");
if (httpRuntimeSec != null)
{
return httpRuntimeSec.MaxRequestLength;
}
else
{
return 0;
}
}
Also add this to your web.config:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1000000" />
</requestFiltering>
</security>
For your 2nd question i will suggest using a client side app so you can validate the file size before uploading, one option could be silverlight
I have a webservice through which I can upload documents to our ASP.NET web site.
The problem is when I upload PDF & word documents, they get corrupted when I try to open them. Text documents always upload fine.
What is even strange is that on my development machine, these files upload fine but when I try to upload to our demo site, they get corrupted.
Any ideas?
my code is of the format:
WebServicesSoapClient proxy = new WebServicesSoapClient();
byte[] data = GetFileByteStream("C:\\temp\\sample.pdf");
string response = proxy.UploadDocument("james", "password",
orderId, "Sample.pdf", data, true);
Are your pdf files larger than 4MB? That is the default maximum request length for ASP.NET. You can override that setting in your web.config with:
<httpRuntime maxRequestLength="8192" />
However, be aware that this will increase your memory usage on your server - by default asp.net will cache the entire request in memory.
Also, I'm not entirely certain this is the problem in your case, since normally this exceeding the request length would cause an exception to be thrown - not silent file corruption.
see also http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626