maxItemsInObjectGraph in asp.net web service? - c#

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

Related

HttpException: maximum request length exceeded, even when config has values that should allow it

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>

MVC 5 C# Window Authentication pop up when I navigate to a certain area

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>

How to increase maxRequestLength per Controller in WebApi

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?

Is there an upload limit when using Web Client in C#?

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.

Confusion in window built in authentication (web.config)

I am currently working with my asp.net project. I use web.config settings to allow and deny services !
It works totaly fine ! Now I got some query ( just for knowledge) that if I use deny and allow authentication both what will happen ?
My code seems like that
<system.web>
<authorization>
<deny users="user_name" />
<allow users="user_name" />
</authorization>
</system.web>
Thanks in advance !
Authorization elements are evaluated in the order they are given in the configuration file.
In your example, the user would be denied, as the deny entry is earlier in the list than the allow entry.
Note that your question is referring to ASP.NET URL Authorization Behaviour (i.e. the settings defined in system.web\authorization). The behaviour of IIS URL Authorization is quite different. See the "Differences Table" here.

Categories