4

I have an ASP.NET MVC5 website and I've generated minified JavaScipt and CSS files with sourcemaps, so I have files in these locations:

  • Scripts/app/all.min.js (all application scripts minified)
  • Scripts/app/all.min.js.map (sourcemap for the above file)
  • Content/css/all.min.css (all application styles minified)
  • Content/css/all.min.css.map (sourcemap for the above file)

Scripts/app/src contains all the original JS files before minification. Content/css/src contains all the original CSS files before minification.

Essentially I want to make sure that in our test, UAT and production environments, the sourcemaps and/or the original unminified files are available only for developers. What I need to do is intercept HTTP Get requests for the sourcemaps or the files in the "src" directories.

How can I achieve this?

I've already tried using:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    // Return 404 if it's not a developer PC here
}

However this event isn't firing for those requests and I'm not sure why. Is there some other way I should be doing this, or do I need to configure my IIS settings?

Thanks very much!

6
  • can't you just exclude the files from being published? Dec 5, 2015 at 13:07
  • No because I want them published for developers to be able to view/debug, I just want to hide them from users who aren't on non-development machines/accounts
    – David Omid
    Dec 5, 2015 at 13:10
  • "published for developers to be able to view/debug" - that's what your testing/UAT environments are for... You don't want your debug code on a production environment. Yes, you can run managed code for even direct file requests, but you only do that if you don't care about performance.
    – CodeCaster
    Dec 5, 2015 at 13:15
  • If a JavaScript error is thrown in our live environment, the error info including a JS stacktrace gets sent to our server. This is useless with minified code though, so as developers we also want to be able to see errors which may only be present in production for whichever reason. If we hide the sourcemaps from non-developers, other users won't be able to see our debug code.
    – David Omid
    Dec 5, 2015 at 13:18
  • 1
    Yeah so you have a reproduction problem, not a debugging problem. Anyway the most straightforward way to do this is by writing an IIS Module that gets run for every request. Then you can inspect whether the requests comes from your local network or from certain whitelisted IPs.
    – CodeCaster
    Dec 5, 2015 at 13:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.