2014年7月13日 星期日

[RESOLVED] bundeling & minification


I converted my entire Web Forms Web Site project (200+ pages) to use bundeling & minification and every page works perfectly except my login screen. The resources get registered fine if I navigate to the login page but if I refresh it, all resources are
unrecognized by the browser as if they were never included even though if I look at the source, they are there.


I fired up the network profiler in IE11 and on a single refresh I get these 3 requests:


1. http://dev/ArgoWeb/Login.aspx?ReturnUrl=%2fArgoweb 

2. /ArgoWeb/bundles/jquery?v=5LT0ASbM4iSwzp2VLfw4Xo23UDm08wjTCtJEL6FxlNc1

3. /ArgoWeb/Login.aspx?ReturnUrl=%2fArgoWeb%2fbundles%2fjquery%3fv%3d5LT0ASbM4iSwzp2VLfw4Xo23UDm08wjTCtJEL6FxlNc1&v=5LT0ASbM4iSwzp2VLfw4Xo23UDm08wjTCtJEL6FxlNc1


(1) is the login page itself. (2) it the bundle included in the page. But request (3) seems to be triggered by the bundle URI not having access, which triggers the login page again. Stepped through the code behind and the login page indeed gets hit twice,
which it shouldn't. I think this is where the problem is. Are the virtual bundeling paths created by the optimization package supposed to be behind the authentication wall? If so how do we use them before the user logs in?


I suspect this is a bug in the optimization pack because this failure only occurs on a manual page refresh not an initial render. Wonder if this is because bundeling is only a first class citizen to MVC and hasn't been tested much with Web Forms.



I figured it out, so here is the solution if others have this problem. You must add this in your web.config making sure the path matches your bundling path.


    






This exempts the virtual directory created by the bundleing and minification framework from requiring forms authentication. I still think its a bug that the framework doesn't do this or does it partially. If bundeling is turned off, the script and CSS includes
ARE exempted, so why not when its on?


沒有留言:

張貼留言