I found the same question here since 2012, but I want to launch again the question.
Is it possible to increase the maxRequestLength per service or controller instead of changing the Web.Config?
<system.web>
<httpRuntime maxRequestLength="10240"/>
</system.web>
If it can't be programmatically, can be done in the Web.Config but it can be focused only for some Controllers?
Related
I can't seem to allow a 4.3MB upload. I keep getting this error:
System.Web.HttpException (0x80004005): Maximum request length
exceeded.
My web.config settings in my Web API:
<!-- maxRequestLength expresses POST buffer size in KB. This is the ASP.NET limit. -->
<httpRuntime targetFramework="4.5" maxRequestLength="20000" />
<!-- Let this be larger than maxRequestLength so we get ASP.NET error (if request too large) instead of IIS error. -->
<requestLimits maxAllowedContentLength="20480000" />
And this is the call to the API from my web project:
var response = await httpClient.SendAsync(proxyRequest);
That always returns the above error. What am I missing? I did read where maxRequestLength needs to be the same value as maxAllowedContentLength, but that didn't work either.
The "Default Web Site" in IIS had a config file with almost nothing in it. I added maxRequestLength="20000" to it and it worked. My app is one of many apps under "Default Web Site."
Added this:
<system.web>
<httpRuntime targetFramework="4.5" maxRequestLength="20000" />
</system.web>
I have an application with multiple areas. I have no problem navigating to any of them once logged in.
I've added a new 'Reports' area, now when I navigate to that area I get an 'Authentication Required' pop up appear which I think is something to do with Windows authentication which isn't being used in the application.
I'm using <authentication mode="None" /> in web.config.
This only happens when the site is live and not local (which makes sense if it's a windows authentication issue).
All controllers in the areas use the same custom authentication attribute, any ideas why I wouldn't be able to navigate to this new area even though going to others is absolutely fine, any ideas what i'm missing? I don't remember having to do anything in other areas to allow access.
Thanks.
I found the issue. The URL that was causing the issue was
www.domain.co.uk/reports
I remembered a while ago I was doing some testing using SSRS and setup the Report Manager URL as localhost/reports. This must have been causing the issue as once I had changed the Report Manager URL I could access the URL I was having issues with as expected.
That setting in your web.config should be working.
It could be that it's not overriding the settings in the applicationhost.config file as it should.
To test this out navigate to the "\IISExpress\config\applicationhost.config" file and set <windowsAuthentication enabled="false" />
Other things you can try.
Remove forms authentication - sites often default to this.
<system.webServer>
<modules runAllManagedModulesForAllRequests="true>
<remove name="FormsAuthentication />
</modules>
</system.webServer>
Disable security for that path.
<location path="secureddir/newform.aspx">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
Using UploadFile("upload.php", "POST", filePath) with WebClient anything over 4mb will not upload. The limit in PHP is set at 48mb. Is there I need to set in C# ?
There is a default maxRequestLength set at 4MB in ASP.NET, you can change it in the web.config.
<configuration>
<system.web>
<!-- This will handle requests up to 1024MB (1GB) -->
<httpRuntime maxRequestLength="1048576" timeout="3600" />
</system.web>
</configuration>
The length is specified in KB in the config file. If you are using IIS there is an additional limit set at 4MB by IIS.
I have solved the problem. By changing the following in the php.ini
post_max_size = 40M
I had already changed the upload_max_filesize but was not aware of this other param which needed changing.
A client of ours is using an asp.net web service (asmx) I created and is getting an error saying the maxItemsInObjectGraph is too small. I told him to make the necessary changes in his app.config file. But where do I have to make these changes on my side?? The web.config file in my web service doesn't mention maxItemsInObjectGraph.
Thanks a lot.
Because it has a default value which is used when it's not in your config. You'll have to either add it to your web.config or to your code as shown here, here, here or here.
EDIT: For ASMX there isn't a setting for maxItemsInObjectGraph, setting the maximum request length might help though.
<location path="yourservice.asmx">
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
</location>
Other properties for the httpRuntime on MSDN
I currently have an ASP.NET MVC project that has file uploading and it works great if the user has a good enough connection and their file is of a reasonable size.
The problem I'm running into is that sometimes a user might have a 56k connection (how they can live with it in this day and age, I don't know) or are uploading a larger file or some combination of the two.
I'd like to keep a small timeout for normal pages (90 seconds or so), but allow for a larger timeout for actions where a user is uploading. This is just one action, so I don't mind putting code inside just that singular action rather than a generic solution.
Ultimately, a solution that would automatically increase the timeout if Request.Files.Count > 0 would be the best.
I'm not sure if this would work in an MVC project, but you could try creating a location in your web.config and set the execution timeout for just your upload URL. For example:
<location path="YourUrl">
<system.web>
<httpRuntime executionTimeout="9001"/>
</system.web>
</location>
You might need to increase the timeout in web.config:
<httpRuntime executionTimeout="01:00:00" />
Now this is overridable in sub web.config files meaning that if you want to increase the timeout only for the uploading script you could write a generic HTTP handler that will handle the uploads and put it in its own subfolder with its own web.config.
Possible issue: If its not a timeout because of the zero activity, maybe its something to do with the built in size restriction, in the web.config httpRuntime section you could add/increase maxRequestLength="" to your size limit