Css bundling with dot in virtual path - asp.net

Kendo configurator installed its css content into "~/Content/kendo/2016.1.226" folder. I need to create the same virtual path in the mvc bundler in order to make it work (see http://www.telerik.com/forums/asp-mvc-css-minification-breaks-kendo-bootstrap).
However, when I create the bundle:
bundles.Add(new StyleBundle("~/Content/kendo/2016.1.226/kendo-css").Include(
"~/Content/kendo/2016.1.226/kendo.common.min.css",
"~/Content/kendo/2016.1.226/kendo.default.min.css"));
I get 403 Forbidden response. Is there a way to make a virtual path containing dot work?
We use .net 4.6.1 and asp mvc 5.
Obviously, the fallback is to rename the folder and all the paths, but I am asking if there is another way.

This is because the name of your bundle (~/Content/kendo/2016.1.226/kendo-css) contains the same path as a physical path.
I would recommend changing your bundle name to something like ~/css/kendo or the like.
You should also use the rewriting then to fix the URLs, for example:
.Include("~/content/css/menusprites.css", new CssRewriteUrlTransform())
More can be found in this Telerik forum post: http://www.telerik.com/forums/asp-mvc-css-minification-breaks-kendo-bootstrap#KBg1hY3Z1EqbutQZxshjow

Related

Referencing assets in ASP.NET Core

I started with an ASP.NET MVC Core 2.1 project. Then, I loaded a 3rd party theme (html/css/javascript/fonts) into wwwroot folder of the project. When I open the .html files from wwwroot, all appears fine.
I now want to "cut" the theme into MVC parts -- _Layout.html, views, etc. When html content is placed into MVC views, do I need to prefix every link with "~"? For example, href="css/colors/orange.css" becomes href="~/css/colors/orange.css"? This seems like a lot of work. Is there any way to tell .NET that relative paths are off wwwroot?
And a related question -- I don't have to use MVC - if I used ASP.NET Core non-MVC project, would this not be an issue?
Thanks.
The tilde is used to resolve virtual folders. For example, if I put my app in a virtual folder app1 in IIS, then href="~/path" would be translated to href="/app1/path". If you aren't using virtual folders then you shouldn't need the tilde.
Additional
href="css/colors/orange.css" is relative to the folder you are in. It is expecting css to be a child of the current folder. If you were to add a leading slash then it would be an implied absolute path with the leading slash being root. href="/css/colors/orange.css" would expect css to be a child of your root folder. If you aren't using virtual folders as explained above you would still need to add a leading slash since css will always be a child of root.

How to reorganize contents like the old school in ASP.NET Core MVC?

I have a web site in ASP.NET Core MVC, and I don't want to put my contents inside another folder. I just want to use the old school of creating this file-system architecture at the root of my project's folder:
Styles
Fonts
Scripts
Images
But I can't make ASP.NET Core MVC serving files from them. For example http://domain.test/styles/default.css returns 404.
I've tried to add StaticFileOptions, but I can't get it to work.
Can you help please?
I tried the given solution, that is, to use UseWebRoot("") with empty string to make it refer to the root of my web project. Yet it still returns 404.
I created a Styles folder inside the \bin\Debug\netcoreapp2.0\ and added a Styles.css there and it served the file.
If you are not adding them on the wwwroot folder then you should do more preparation.
This link will help Working with static files in ASP.NET Core
I think before asking you should search some more. For example
this stackoverflow question will help you:
How to Configure an Alternative Folder to wwwroot in ASP.NET Core?

Bad resources path in ASP.NET MVC5 page

This is curious.
When I have this, for example, in my BundleConfig class:
bundles.Add(new StyleBundle("~/iCheck/css").Include(
"~/Content/iCheck/flat/green.css"));
bundles.Add(new ScriptBundle("~/iCheck/js").Include(
"~/Scripts/icheck.js"));
In a server, resources are retrieved from the correct location:
/Content/iCheck/flat/green.css
however, in other server, resources are retrieved using this URL:
/iCheck/css?v=ENsQ8JbHO7Zzp1Za0G2FBDKGGsGf_VDHd_S5fgCyCxA1
That causes images inside the CSS not to be found. How can I solve it? in both servers there is the same deployed version of the site. I don't understand why in one server the bundles behave different from others.
Bundling is enabled for Release builds but not for Debug.
The property BundleTable.EnableOptimizations will allow you to override the bundling setting in development.
To fix the relative paths within the CSS look at the CssRewriteUrlTransform.
.Include("~/Content/iCheck/flat/green.css", new CssRewriteUrlTransform())

Is there a way to use external javascript/css in VS2012 bundling?

It's pretty much in the title but to re-iterate: Is there a way to use Visual Studio's built in bundling to grab scripts from an external domain?
If not directly, would there be a way to include js/css files from an external domain within the sln so that bundling would work?
The question stems from the desire to have a domain which contains common javascript libs/snippets that can then be used by several other sites. All sites and files are owned and run by the same company.
Any help would be appreciated.
As Jasen said, a CDN is what you're describing. I know this is old but I found it on a search of the topic so I'm going to submit an example for those who also find it.
Here's a normal BundleConfig entry:
bundles.Add(new ScriptBundle("~/bundles/js").Include(
"~/lib/jquery/jquery.js"));
Here's the overload to ScriptBundle that allows using a CDN:
bundles.Add(new ScriptBundle("~/bundles/js", "https://code.jquery.com/jquery-3.1.0.min.js").Include(
"~/lib/jquery/jquery.js"));
BundleTable.EnableOptimizations = true;
bundles.UseCdn = true;
It's an overload of ScriptBundle, with the second string argument being the CDN URL. You also have to add the two flags following.

Umbraco - Get Directory of Config Files

I'm working with Umbraco 4.7.1 and I've created some extensions that hook into Document.AfterPublish and Document.AfterUnPublish. I need to find the directory of the config files from here, but need to be independent of server installation (i.e. a literal won't work). Is there any way of finding this at that point in time?
I think what you are looking for is the umbraco.IO.SystemDirectories class, specifically the Config property.
This will return "~/config" by default, but can be overridden by adding a umbracoConfigDirectory key to the appSettings section of the web.config file and specifying a different path there.

Resources