Thursday, November 13, 2014

.js normal reference to embedded file authentication issue in .net

I had written a fairly complex paging object in javascript for a custom reporting system built on the .net platform.  It was all bundled up as an embedded resource for the custom system but I wanted to re-use it for another part of the site that suddenly needed to do paging.

When I first added the file reference in the head of my HTML document everything was working great.  But an hour or so later I started getting javascript reference errors saying there was a syntax issue inside the file.  I looked at what my browser was referencing as the file and discovered that it was getting an authentication denied page instead.

It turns out that .net handles embedded resources a little differently than normal files; which is to be expected since they get bundled up in the dll.  I was just expecting a second copy of my .js file to remain in its folder in addition to getting bundled, but it would seem that .net protects that file.

I was able to get my basic reference working correctly by navigating to the reporting pages which reference the embedded resource.  Once the reporting system had correctly authenticated and downloaded the embedded .js file then my other page was able to use it until that authentication ran out.  The long term fix of course it to add an embedded reference to the file on the new page as well.