0

I'd like to change the maxAllowedContentLength for a specific method of a controller. I've been able to set it at the controller level, but can't figure out the syntax for the method. I'm not sure if this is possible. So the relevant section of my web.config file looks like:

<location path="Controllers/MyController.cs">
    <system.webServer>
        <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
        </handlers>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="52428800" />
            </requestFiltering>
        </security>
    </system.webServer>
</location>

My method inside Controllers/MyController.cs looks something like:

public async Task<JsonResult> MyUpload() {
   //Do stuff here
}
8
  • I don't think you can do that for specific methods in a .NET Framework app. I believe the location element is really only used for actual files and directories.
    – DavidG
    Commented Aug 6 at 12:17
  • This question is similar to: How do I allow all users access to one route within a website with integrated auth?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
    – DavidG
    Commented Aug 6 at 12:23
  • I don't really think the he Authorize attribute, as suggested in the solution to your question, is going to help me here. It might just not be possible to narrow it down to a specific method.
    – Eric
    Commented Aug 6 at 12:51
  • It definitely wouldn't be right to provide a path to a C# file. Remember, your ASP.NET Core app is going to get compiled into DLL's, there is no C# file in the actual build artifact that you'd run on a server.
    – mason
    Commented Aug 6 at 14:14
  • Is this actually ASP.NET Core though? There is no web.config in that framework. If it really is .NET Core, then you may be able to use an attribute e.g. [RequestSizeLimit(1234)] on the controller action.
    – DavidG
    Commented Aug 6 at 14:29

0