Jonny H
Jonny H

Reputation: 31

MVC 4 bundling broke when published as IIS7 application

I'm attempting to deploy an MVC 4 project onto IIS 7.

I need the project to be an application inside a website so that users can continue to use an existing site but access mine by adding /mySite to the existing URL.

I can get access to my site when created as an application under a website but all bundles are broke.

When I view source my bundles don't have a value, so the src of scripts look like:

"/mySite/Scripts/validation?v="

If the application is published as a separate website and not an application it works ok and bundles have a value.

"/Scripts/validation?v=-_ZaBIp4vfIoajyi-JkBIsoCXRGuEGptU4ZUpHA6c8U1"

Below is how I define my bundles in bundle config.

        var validationBundle = new ScriptBundle("~/Scripts/validation")
            .Include("~" + Links.Scripts.jquery_validate_js)
            .Include("~" + Links.Scripts.jquery_validate_unobtrusive_js);

I have checked the app pool of the parent web site and this is set to .NET 4

I'm at loss and cant find anything else online so any suggesstions welcome.

Thanks

ANSWER

Typical, I ended up finding the answer on another stack overflow question which I have lost again so no link.

The problem was using T4MVC, this generates incorrect paths for an MVC project being published as an application or in a virtual directory.

You can continue using T4MVC if you are publishing as a website, as the paths will be correct.

Upvotes: 3

Views: 1743

Answers (2)

Mohsen Musavi
Mohsen Musavi

Reputation: 54

Use VirtualPathUtility.ToAppRelative to create application-relative path in IIS,like this:

  var validationBundle = new ScriptBundle("~/Scripts/validation")
        .Include(VirtualPathUtility.ToAppRelative(Links.Scripts.jquery_validate_js))
        .Include(VirtualPathUtility.ToAppRelative(Links.Scripts.jquery_validate_unobtrusive_js));

see this question: Unable to generate 'VersionQueryString' in Scripts.Render when using bundle

Upvotes: 0

Michael Samteladze
Michael Samteladze

Reputation: 1330

 <system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/> 
 </system.webServer>

This modification in web.config file, worked for me.

Upvotes: 2

Related Questions