I'm developing ASP.NET MVC Razor project using monodevelop 5.9.6 and I added all packages necessary for bundling (System.Web.Optimization), in BundleConfig I'm adding
bundles.add(ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
and others. In Global.asax.cs I'm calling
BundleConfig.RegisterBundles(BundleTable.bundles);
However in _Layout.cshtml
#Scripts.Render("~/bundles/jquery")
is rendering as
<script src="/bundle/jquery?v=5GM9HLcujnDGm6SNVq0Es63_cXK2viQ4_nYEpm02Ls1"></script>
when running, causing "Failed to load resource (404)" javascript error, because all jquery's files are not rendered as it should be.
I need to render all jquery files and style files.
It's a feature of Bundling and Minification. All of jquery and css file grouped into one file when you enable Bundling and Minification and it works in two conditions
protected void Application_Start()
{
//Enabling Bundling and Minification
BundleTable.EnableOptimizations = true;
}
<compilation debug="false" targetFramework="4.0">
IF you want each file render separately use
compilation debug = "true" and
BundleTable.EnableOptimizations = false;.
But it's not a good practice when deploying code to production server.
Why 404 : If you can share your rendering code for jquery and css file I can try why 404 error is coming.enter code here
Thanks
Related
I'm building the ASP.Net Core Web Application
I installed bootstrap using Quick Install Package. So now I have it in my dependencies:
Also, there's a folder "node_modules" with bootstrap and everything is fine there, all classes are where they're supposed to be:
Then I created a view and in html wrote the following:
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" />
When I hover the mouse over the href, I see a warning:
Path C:\Users\Shep\SportsStore\SportsStore\wwwroot\~node_modules not found
Well, it's true, because there's no such folder, but how to keep it from looking in wwwroot and use the specified folder? My wwwroot is empty, I guess it's because I didn't use bower
If I use the full path (href="C:/Users/Shep/SportsStore/SportsStore/node_modules/bootstrap/dist/css/bootstrap.css"), it seems right, but I bootstrap classes are unavailable:
<body>
<div class="panel-info">
</div>
</body>
and if I hover the mouse over, I see "Unknown CSS class 'panel-info'" even though there's this class in bootstrap.css
.panel-info {
border-color: #bce8f1;
}
I'm not using Angular and haven't created any js files of my own yet.
I have seen lots of similar issues and haven't found suitable solution, sorry if it's a duplicate
In ASP.NET Core, the runtime supports a piece of middleware called StaticFiles that allows anything in the /wwwroot folder to be accessible from the browser. But since the node_modules directory is outside of /wwwroot ,that problem occurs .
You can use Library Manager/Bundler and Minifier to copy the files into wwwroot . There are a lot of solutions you could find from here .
I'm having troubles with my style sheets bundling after deployment to IIS.
I've created a simple solution to demonstrate my problem.
I've created a simple test project (VS 2012, MVC 4) with a single controller and a view containing an "Hello World" string.
I've created a (test) CSS under the content folder with simple simple color changing
Content\helloWorldCss\helloWorldStyle.css
Then, I've edited my BundleConfig.cs class and added the path to my CSS as a new bundle:
bundles.Add(new StyleBundle("~/Content/helloWorldCss").Include("~/Content/helloWorldCss/helloWorldStyle.css"));
Then, I've added the new bundle to my the _Layout.cshtml:
#Styles.Render("~/Content/helloWorldCss")
When I run my application via VS (or Page inspector) my CSS is being applied successfully and everything seems to be OK. However, when I publish/deploy my project to IIS (through VS), I can view my HTML but my CSS is not being applied.
The following file exists after deployment:
Content\helloWorldCss\helloWorldStyle.css
What really puzzles me is that when I alter my _Layout.cshtml and add a "regular" ref to the same CSS instead of using the bundle ref, the CSS is applied after publishing without any issues.
<link href="#Url.Content("~/Content/helloWorldCss/helloWorldStyle.css")" rel="stylesheet" type="text/css" />*
I will appreciate any help and advice on this.
I think you've got a name collision here. ASP.NET MVC will create a file on http://example.org/Content/helloWorldCss after minification and you already have a folder with the same path. Can you try it again after renaming your bundle?
BundleConfig.cs:
bundles.Add(new StyleBundle("~/Content/helloWorld").Include("~/Content/helloWorldCss/helloWorldStyle.css"));
_Layout.cshtml:
#Styles.Render("~/Content/helloWorld")
This is what i do.
IIS Config>Authentication>RightClickOn Anonymous Auth>Click Edit> Check Application pool identity
When you use VS publish to a test server, it uses defaultAppPool.
For the styling and SimpleMembership to work you need:
Install ASP.NET 4.0 on your server.
cmd -- cd C:\Windows\Microsoft.NET\Framework\v4.0.30319\
Type aspnet_regiis.exe -ir
Add an ASP.NET 4.0 app pool in IIS.
Set your site to use ASP.NET 4.0 as app pool.
Add an ASP.NET 4.0 security login in SQL Server and give it dbcreate role.
My MVC4 application is using Scripts.Render to load a bundle that is loading a file called "functions.js."
When I debug this application in the browser, the script loads, but the version is outdated. When I view the resource directly, but append ?v=anytext the script looks correct, but without that appended, the script shows the old code. Is there a way to force the bundling to output the correct file instead of a stale one?
This is likely a caching issue. When using Bundling and Minification in debug mode (when <compilation debug="true" /> is set in your web.config), bundling/minification is disabled.
You can override this and force bundling and minification by adding BundleTable.EnableOptimizations = true;. This will make it act like it will in your production environment, where everything is bundled and minified, and the script reference includes that versioning parameter (like you gave) that will force the browser to reload your scripts when anything changes.
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
//all your bundle code
BundleTable.EnableOptimizations = true;
}
}
I have an ASP .NET MVC 4 app with BundleConfig.cs in the App_Start folder and a call to this class and the RegisterBundles method within the Global.asax.
Everything works fine regarding the Script bundling, but the style bundling produces nothing.
var bundle = new StyleBundle("~/bundles/css")
.Include("~/Themes/Rikkle.Web/Styles/app.min.css");
BundleTable.Bundles.Add(bundle);
I access the above bundle on the page like so:
<link href="/bundles/css" rel="stylesheet" type="text/css"/>
I am manually calling the link as opposed to using #Styles.Render() because the page output NOTHING when I call this (again, all script bundling still works). When I go to localhost:xxx/bundles/css in the browser I get a Status Code of 200, everything is fine, just that the payload is nothing. When I go to localhost:/themes/rikkle.web/styles/app.min.css in the browser, it pulls up without an issue.
Also, I am referencing System.Web.Optimization, the latest drop from Nuget, in both my views folder web.config and the main web.config.
This question is answered by: Bundler not including .min files
Essentially, if you have "min," as in "app.min.css," then the bundling blows up.
I have this ToolkitScriptManager in my Master page:
<asp:ToolkitScriptManager runat="server" EnableScriptGlobalization="false" ID="scrptManager"
LoadScriptsBeforeUI="false" ScriptMode="Release" EnableCdn="true">
</asp:ToolkitScriptManager>
Notice the ScriptMode="Release" and I have compilation debug="false" in my web.config
However, when the scripts get download to the client I get unminified javascripts. The ToolkitScriptManager downloads scripts from:
http://ajax.aspnetcdn.com/ajax/4.0/1/WebUIValidation.js
http://ajax.aspnetcdn.com/ajax/4.0/1/WebForms.js
How do I modify my ToolkitScriptManager to download minified version of these scripts?
This is just a theory. By check the following:
http://ajax.aspnetcdn.com/ajax/4.0/1/WebForms.js
vs
http://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js
I noticed the MicrosoftAjax.js file it is minified, however the WebForms.js file is not. I think your set up for the ToolkitScriptManager is correct and there are some issues with cdn conent. Again it's just a guess, to be sure, maybe you can ask on asp.net forums: http://forums.asp.net/
Hope this helps.