Geeks With Blogs
James Norman
Technically, this is two topics and not one.  But I happened to run into both today while transposing a project I wrote in Java to ASP.Net MVC and while easy to solve, did cause a bit of frustration.

Topic #1: Static JSON Files
I work with a HTML/JavaScript product that requires an XMLfile for configuration, which in turn points to another XML file and two JSON files which reside in the content folder.   The XML itself is generated by an external component and that component has to be passed URLs that point to the files in the content folder.  

I was a little surprised when "~/Content/myfilename.json" didn't work.  Well this was a minor issue as it had to do more of which folder the JavaScript was making the call from, and it had gone with a relative location that looked more like this  http://myServer/test/mainFolder/js/~/Content/myfilename.json rather than going to the root of the website and then finding the Content folder like I expected.

Okay, no problem, I just changed the URL to use "../../Content/myfilename.json" and all was well.  Except that it wasn't...  My URL was resolving to http://myServer/test/Content/myfilename.json - exactly what I wanted.  But I was still getting a 404 error.   Why, IIS Express, why??

Seems I forgot a step, there's a staticContent section under system.WebServer that needs to be added.  I then added an entry for both JSON and XML:

      <mimeMap fileExtension=".json" mimeType="application/json" />
      <mimeMap fileExtension=".xml" mimeType="application/xml" />

Something unexpected happened - IIS Express 7.5 threw back a 500.  Thankfully the grandchild error message was clear:

Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.xml' 

Oh, okay, for some reason IIS Express has that setting but not the one for JSON.  Removing the XML entry fixed the issue.

Topic #2:Uploading Large Files
As part of working with the same software, large documents have to be uploaded to the server sometimes.  And sometimes, you run into this

Maximum request length exceeded.

Okay, no biggie.  Just go into the httpRuntime element under system.web and add this
    <httpRuntime targetFramework="4.5.2" maxRequestLength="2147483647"/>

This, by itself, worked.  However I did add this second bit as a safety under system.webServer/security/requestFiltering as it was mentioned elsewhere, but it didn't seem to be needed. 

   <requestLimits maxAllowedContentLength="4294967295" />

Posted on Thursday, May 5, 2016 3:33 PM ASP.Net MVC , maximum request length exceeded , maximum request length , large files , static files , static | Back to top

Comments on this post: Static JSON files and Uploading Large Files in ASP.Net MVC

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © James Norman | Powered by: