locked
web.config <location path> not working RRS feed

  • Question

  • User-943250815 posted

    I have to set a non default file upload max size, in article from Jon Galloway "Large file uploads in ASP.NET" (https://weblogs.asp.net/jongalloway/large-file-uploads-in-asp-net). He shows not only how to do it, but you can restrict a large upload to specific folder of your site.

    Made my try, but.... there is something wrong with "path", it doe not work and no error message.

    <location path="~/Upload/Email>
      <system.web>
        <httpRuntime executionTimeout="110" maxRequestLength="15000"/>
      </system.web>
    </location>

    Most examples shows just a single folder, in this case I have to go 2 levels deeper, but it is not working.

    Remove "~" is not acceptable due to: <location> path attribute must be a relative virtual path.  It cannot start with any of ' ' '.' '/' or '\'. error
    Use just "Upload/Email" does not work.
    Create a web.config at Upload/Email, is not an option, such folder is just for temporary files, all files are deleted after read

    Is there anything wrong with path syntax?
    Such definition does not work locally?

    Wednesday, April 5, 2017 1:22 PM

All replies

  • User753101303 posted

    Hi,

    Try http://stackoverflow.com/questions/8605925/asp-net-mvc-are-maxrequestlength-and-maxallowedcontentlength-ignored-in-a-subfol and configure as well maxAllowedContentLength (not that this one is in bytes).

    The catch is that you have both an ASP.NET level and an IIS level configuration value (and the IIS default seems to be around 30 Mb which might explain why John Galloway didn't thought the IIS configuration might need to be changed as well if going beyond 30 Mb on the ASP.NET side).

    Edit: ah, was surprising but actually it is mentioned in his article. Seems more expected now that you missed that rather than Jon Galloway ;-)

    Wednesday, April 5, 2017 5:25 PM
  • User-943250815 posted

    Thanks PatriceSC

    I will give try adding to section <system.Webserver>.
    But considering IIS limit is about 30Mb, ASP.Net File Upload Control is limited to 4Mb and my need is in between 10~15Mb, I suppose it was not necessary inform <system.Webserver>.

    But, since I´m just testing locally, not on server, just running my website from IDE, it was supposed to work as is, but it is not.

    On the other hand, your link tell me not alone.
    I´ll keep looking for a solution

    Wednesday, April 5, 2017 6:54 PM
  • User-2057865890 posted

    Hi jzero,

    Most examples shows just a single folder, in this case I have to go 2 levels deeper, but it is not working.

    The main attribute on location tags is "path". The values can be:

    • "." (or ""): Meaning the current level. Typical location paths are set at the global level, and so "." means the global level; however, they can be set anywhere in the configuration file hierarchy. This is also the default value, if "path" is not set.
    • "sitename": The root application of a specific site.
    • "sitename/application": A specific application of a specific site.
    • "sitename/application/vdir": A specific virtual directory of a specific application of a specific site.
    • "sitename/application/vdir/physicaldir: A specific physical directory. The path could be more complex, in the form "sitename/app/vdir/p1/p2/p3".
    • "sitename/application/vdir/file.ext": A specific file. The path could be more complex, in the form of "sitename/app/vdir/p1/p2/file.ext", or less complex, in the form of "sitename/app/file.ext" or "sitename/file.ext".

    Best Regards,

    Chris

    Thursday, April 6, 2017 4:36 AM
  • User753101303 posted

    Ah, so the current situation is that it works with a 2 Mb document but still fails with a 5 Mb document ? I assume the path is correctly written in your file ? (you have a missing ").

    Thursday, April 6, 2017 2:05 PM
  • User-943250815 posted

    Chris, thaks
    But, my attempts was
    path = "/Upload/Email"
    path = "Upload/Email"
    path = "~/Upload/Email"

    The point is, where goes sitename? And what value it should have instead "~", can you give a real sample?

    One more thing, I did not try put everything to work on Server, I´m still running website from IDE, if it does not work on IDE will not on Server

    Thursday, April 6, 2017 2:46 PM
  • User-943250815 posted

    PatriceSC,

    For the first question, yes, when you use File Upload Control, you limited to 4Mb, so if I want upload 5Mb, have to add "maxRequestLength" in web.config.
    After that I can upload 5Mb or any size <= maxRequestLength.

    At this point, there is no restriction, because there is no folder restriction, it applies to any folder of website.

    For the second question, I´m considering path is correct, but everytime I use <location path=XYZ/ABC> it do not work.
    My attemps was:
    path = "/Upload/Email"
    path = "Upload/Email"
    path = "~/Upload/Email"

    One more thing, I did not try put everything to work on Server, I´m still running website from IDE, if it does not work on IDE will not on Server

    Thursday, April 6, 2017 2:46 PM
  • User-2057865890 posted

    Hi jzero,

    Chris, thaks
    But, my attempts was
    path = "/Upload/Email"
    path = "Upload/Email"
    path = "~/Upload/Email"

    The point is, where goes sitename? And what value it should have instead "~", can you give a real sample?

    In IIS, if we had a web application deployed as follows:

    xxx (root node)
        AppPools (application pool node)
        Sites (website node)
            Default Web Site(site name) 
                MyApplication
                    vdir1 (virtual directory path = /vdir1)
    upload
    email

    The specific physical directory should be

    <location path="Default Web Site/MyApplication/vdir1/upload/email" >

    Best Regards,

    Chris

    Monday, April 10, 2017 9:28 AM
  • User753101303 posted

    I would so something such as :

    - put this in a web.config file in this folder and check those settings are working as expected

    - then if you want to keep that in a centralized file create may be a test page to double check what is the exact vitual file from this path and move this in your main config file, deleting then the folder level web.config file

    Monday, April 10, 2017 9:41 AM