When you use bundles. Add methods when adding Stylebundle and Scriptbundle objects, be sure to note that The parameters of the Stylebundle and Scriptbundle constructors virtualpath the specified virtual path must not be a real folder path in the current ASP. NET project, or when you deploy your site to IIS, you will find that the MVC page uses the @ The URL paths generated by Styles.render and @scripts.render are rejected by IIS, and IIS prompts you to prevent access to the 403 error.
Here is a foreigner encountered the same problem in the StackOverflow forum on the question:
My MVC 4 application works fine on my local computer.
However, the CSS files is not working after I publish (is not affecting the layout of the website).
I can see CSS the files is on the server.
When I look at the source code, I can see
<link href= "/content/css?v=fxcdhaogpdvcroxkmfewgqggo9ucfzckn3pan8boizi1" rel= "stylesheet"/>
Where as on my local computer, the source code shows as
<link href= "/content/css/myfile.css" rel= "stylesheet"/><link href= "/content/css/myfile02.css" rel= " Stylesheet "/>
So, with the source code view on the server, I clicked on and the Content/css?v=fxCdHAOgPDvcROxkMfEwGQggO9uCfzckN3PaN8BOIzI1
browser took me to a 403-forbidden:access is den Ied.
I am Adding the CSS files with the BunldeConfig.cs class
public class Bundleconfig { //For more information on bundling, visit http://go.microsoft.com/fwlink/? linkid=254725 public static void Registerbundles (Bundlecollection bundles) { bundles. ADD (New Scriptbundle ("~/bundles/javascript"). Include ( "~/scripts/1.9.1.js", "~/scripts/jtools.js", "~/scripts/script.js" )); Bundles. ADD (New Stylebundle ("~/content/css"). Include ( "~/content/css/website.css", "~/content/css/banner.css", "~/content/css/reusable.css", "~/content/css/lists.css", "~/content/css/tooltip.css", "~/content/css/overlay.css" );} }
My question is, assuming this isn ' t a IT issue with the server (IT had been working fine until recently) is there Somethi ng wrong with my code?
The expert's answer at the StackOverflow forum:
Your problem is, the using ~/content/css as a bundle alias in the new Stylebundle ("~/content/css"), while the This pat H actually exists.
So when is requesting <link href= "/content/css?... > You is essentially asking for a directory listing and that is forbidden.
Try using something else, like New Stylebundle ("~/content/styles").
Note: If you don't use the something like ~/content/styles as an alias your may has issues with the relative URLs in your. css files. It may be seem odd, but the better use something like ~/content/css/somealias
This means that the virtual path defined when constructing Stylebundle and Scriptbundle cannot be the physical path that exists on the server, and the expert also mentions that Stylebundle's virtual path is best not to use ~/content/styles. Because this may cause problems with access to the. Css file, it is best to use ~/content/css/somealias as the virtual path for Stylebundle.
StackOverflow Original Address
Bundles attribute in ASP. MVC4 Server denied access (403 error)