Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net MVC Bundling on Login Page

I have an Asp.Net MVC site that uses forms authentication and has no 'public' access. Unauthenticated requests redirect to my Login controller. In the View I am referencing css and js files via Bundles. However, when deployed, the requests to these bundles all redirect to the login page with a RedirectUrl parameter. Make sense?

So, how can I get specific bundles to be accessible without authentication being required?

As a poor workaround I know that I can just reference the individual files placed in a public folder - but this circumvents all the minimising benefits.

Thanks.

like image 698
Chris Arnold Avatar asked Feb 22 '14 10:02

Chris Arnold


1 Answers

There are a couple of things you need to do.

First, change the name of the scripts and styles you want to render to be something that doesn't conflict with a folder in your application. So if you have ~/Content/styles folder, name your style bundle something like ~/Content/styles/css.

The /css at the end of the bundle name is to prevent the request from being treated like a script.

Second, you need to add authorization for the Content or whatever you call your bundle path as referenced in your web.config

<location path="Content"> <!--or whatever you call your bundle path instead of Content-->
  <system.web>
    <authorization>
      <allow users="*" />
    </authorization>
   </system.web>
</location>

This will prevent the forms authentication redirect and serve up your content.

like image 94
Brian Dishaw Avatar answered Sep 28 '22 03:09

Brian Dishaw