Reputation: 14971
I have an MVC project in Visual Studio 2013 that loads a view and gets a 404 error when loading a bootstrap stylesheet. I'm using IIS to host my site and I have a virtual folder called "content" which points to a network drive for images, uploads, etc. In my Visual Studio project, I imported bootstrap via the NuGet package manager. The Bootstrap stylesheet is located at
/content/bootstrap.min.css.
I've tried using
* @Url.Content("~/content/bootstrap.min.css")
* "~/content/bootstrap.min.css"
* "/content/bootstrap.min.css"
but nothing is working. The extact message I get is
GET http://mysite/content/bootstrap.min.css 404 (Not Found)
The script files are being imported properly, so this leads me to think something funny is going on with my virtual folder and my project's content folder.
Has anyone else encountered an issue like this and if so, what was the solution?
UPDATE: I copied all the files in my project's "content" folder into the virtual directory and now I'm not getting any 404 errors. This isn't an acceptable solution. Any suggestions?
Upvotes: 0
Views: 1354
Reputation: 14971
It turns out that creating a virtual directory named "content" requires that any files inside the project's content folder must be present in the virtual directory as well. For example, let's say we have a network drive with the path \ContentHost\Content that is mapped as a virtual directory named "content" in IIS. In our project we also have a folder named "content". If you use NuGet and get a JavaScript library that places some files into the project's content folder, you have to manually copy those files to \ContentHost\Content in order for them to be recognized by IIS. This is because IIS is looking in \ContentHost\Content and not the project's content folder. If you're using NuGet and upgrade your libraries, you'll have to ensure the files in \ContentHost\Content and the project's content folder are in sync. This isn't the end of the world, but it does impose another manual process which can result in a point of failure if you forget to do this.
Upvotes: 0
Reputation: 456
When you create an MVC Project from within Visual Studio 2013, you should not have to manually create any virtual directories when you try to host your Application within IIS.
You should use the Publish Feature from Visual Studio and point it to your IIS. Letting VS manage the deployment to IIS ensures all your HTML/CSS/JS is deployed to the appropriate locations.
Here's a link that walks you through the deployment steps. ASP.NET MVC
Upvotes: 1