Friday, 23 December 2011

My ASP.NET MVC Page (using Forms Authentication) is not Rendering CSS and Javascript on the Login View - All Requests Show as Redirects to the Login Controller Action in Fiddler

I recently tried to deploy an ASP.NET MVC 4 mobile application (using jQuery Mobile 1.0) to one of the Oakton Amazon Web Services (AWS) web servers. This application used Forms Authentication.

I span up a completely new instance of Windows Server 2008 R2, restored a backup database and xcopy deployed the new application to a newly created Virtual Directory. I ran the Microsoft Web Platform Installer to get the latest MVC framework and supporting components.  I enabled Forms And Anonymous Authentication on that IIS 7 Site and made sure that All users can access the CSS files even before logging in with the following entries in the web.config file:

<location path="Content">
            <system.web>
                  <authorization>
                        <allow users="*" />
                  </authorization>
            </system.web>
      </location>
      <location path="Styles">
            <system.web>
                  <authorization>
                        <allow users="*" />
                  </authorization>
            </system.web>
      </location>
      <location path="Scripts">
            <system.web>
                  <authorization>
                        <allow users="*" />
                  </authorization>
            </system.web>
      </location>

However, when hitting this server, the login screen just wouldn't render correctly. Looking at the requests showing up in Fiddler - it seemed that even the CSS and javascript files were being redirected to the login page. Some of my colleagues had a look - but were also stumped. All the permissions looked right!

While the application pool user had the correct permissions, the problem was that Anonymous users (i.e. everyone before login) were not running as the Application pool user - they were still running as the default which is IUSR. I simply edited the Anonymous authentication credentials setting in IIS 7 to use the Application Pool Credentials rather than IUSR. Alternatively, I could have given the IUSR_MachineName user permissions on the required supporting directories to fix the problem.


This resolved the problem - and CSS and jQuery were again accessible for all users (including anonymous ones). As usual this seems pretty obvious in hindsight - but the mad rush to get the whole environment running and to deploy the application meant that this critical link was missed.

Let this be a reminder.
DDK

4 comments:

nhuthuy said...

Thanks for sharing, nice post! Post really provice useful information!

Giaonhan247 chuyên dịch vụ chuyên dịch vụ mua hàng trên Amazon ship về Việt Nam uy tín, dịch vụ ebay vn nhanh chóng và dịch vụ order hàng Mỹ uy tín.

Yes done - Best Professional On Demand Home Service Provider in Jaipur said...

Thanks for sharing this information.
Yes Done is the best online site for on demand home services, professional service providers in Jaipur, Rajasthan. We are providing top services like carpenter, cleaning, TV, best pest control services in Jaipur, ro repair service in Jaipur, ac repair service in Jaipur online by Yes Done is there for services at your doorstep in Jaipur, Rajasthan. For more service visit our website. For more services visit our website.

GIEC Global - Best Migration Agent Melbourne & Education Consultant in Melbourne, Australia said...

It's a great blog, shares a piece of good information.

GIEC Global is the leading education and migration consultants in Australia. We are top Education consultants in Melbourne, Sydney, Perth, Brisbane, Adelaide and Australia. We are best education consultants for Canada in Australia. We also helps people in studying in USA and have been awarded as education consultants for USA in Melbourne and education consultant for UK in Australia.

GIEC Global - Best Migration Agent Melbourne & Education Consultant in Melbourne, Australia said...

The awesome blog shares good information with everyone. I will bookmark it in the future.

France Education Consultants in Australia is GIEC Global. We are top Education consultants for Norway in Melbourne, Sydney, Perth, Brisbane, Adelaide and Australia. We are best education consultants for Netherlands in Australia. We also helps people in studying in Ireland and have been awarded as education consultants for Ireland in Melbourne and education consultant for Finland in Australia.