I'm trying to use the bundling features of System.Web.Optimization to minify my css and java script.
I have installed the pre release via NuGet
Install-Package Microsoft.Web.Optimization -Pre
and added the following references to my web.config files
/Views/Web.config
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
.....
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
/Web.config
<pages>
<namespaces>
.....
<add namespace="System.Web.Optimization" />
</namespaces>
</pages>
I am adding bundles like so
bundles.Add(new StyleBundle("~/Styles").IncludeDirectory("~/Styles", "*.css"));
bundles.Add(new ScriptBundle("~/Scripts/App").IncludeDirectory("~/Scripts/App", "*.js"));
and rendering to my page like this
#Styles.Render("~/Styles")
#Scripts.Render("~/Scripts/App")
Which works great until I turn off debug
<compilation debug="false" targetFramework="4.0" />
The link and script tag added to my page are
<link href="/Styles?v=NMwU-eYeuzJZeywD3xbes6ngUXXJURhda30SEe9mb7Y1" rel="stylesheet">
<script src="/Scripts/App?v=NIL6McOTiWu9OPTVvgMfbmjFtYQhKZDQpRIbKK2kzSk1"></script>
Looking at Chromes network tab I get a 302 redirecting to
/Styles
/Scripts/App
Followed by a 404 :(
I can't seem to get this to work.... has anyone seen a similar issue?
Do you maybe have a conflict with your routing code?
Rick Anderson has a blog post about the bundling / minification features, including a note that you must be careful to avoid routing conflicts. You haven't posted your routing section, but it's something to take a look at.
Related
This is my web config
<configuration>
<connectionStrings>
<add name="vmpcon" connectionString="data source=localhost;Database=XXXX;User ID=XXXX;Password=XXXX; Trusted_Connection=False;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
I have one page on that site, and when I navigate to it, I got just the html without any css affects and without the images.
I tried using chrome to check if there is any error on console but there is no error on console
I choose integrated on IIS, but If i choose classic, the page becomes empty.
help me to load the css and images please?
if you need more information tell me please
IIS 6.1
Update 1
In chrome, I see that the type of the css file is text/plain though I declare it like this:
<head runat="server">
<title>YMC Popup</title>
<link rel="stylesheet" href="css/style.css"/>
</head>
Enabling static content via server manager was the solution
My application has this structure
MyApplication
-Themes
In my application's webconfig I remove the UrlAuthorization module and add my own:
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlAuthorization" />
<add name="MyModule" type="MyType, MyNamespace" preCondition="managedHandler" />
</modules>
My Theme folder has this webconfig (this is the complete webconfig):
<?xml version="1.0"?>
<configuration>
<system.web>
<pages styleSheetTheme="" validateRequest="false" />
</system.web>
</configuration>
I have this deployed in 3 environments. 2 of them works correctly but in one of them I have the UrlAuthorization module working when I make a request do a file inside the Theme folder.
I know that the UrlAuthorization is active because I do not get the resource I requested, but an URL /ReturnURl/... path
The < remove> tag is working because removing it causes the whole request to be redirect to the /ReturnUrl
Is there any reason that may cause this behavior to happen only in this machine?
I deployed all of them and I do not remember making and different task on any of them
thanks!
FYI, it was an issue due to the folders permissions in the file system. I made the environments identical and it worked.
I am using dotLess.
I followed all their instructions (which seems simple enough) it's only 4 steps :)
my minimal web.config looks like this:
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler,dotless.Core" />
</configSections>
<dotless minifyCss="false" cache="true" />
<system.web>
<httpHandlers>
<add type="dotless.Core.LessCssHttpHandler, dotless.Core" validate="false" path="*.LESS" verb="*" />
</httpHandlers>
</system.web>
<system.webServer>
<handlers>
<add name="LessHttpHandler" type="dotless.Core.LessCssHttpHandler, dotless.Core" preCondition="integratedMode" path="*.less" verb="*" />
</handlers>
</system.webServer>
</configuration>
I've added my .less files in my content folder (i am using ASP.NET MVC - Razor ViewEngine)
my layout has a link to my .less include file:
<link rel="stylesheet/css" type="text/css" href="#Url.Content("~/Content/Site.less")" />
I have also added the a reference in my web application to dotless.Core.dll
Yet despite all of the when i do a simple styling of the page's body backround to black, nothing happens, for some reason it aint kicking in.
Am i missing something here?
Do you set the httphandler to run on requests? Add this:
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"></modules>
</system.webServer>
</configuration>
have you tried accessing the Site.less file directly with your browser? If there is a syntax error in your less it will be output there..
If you get a 404 on that page the web.config is the problem, but I can't find anything wrong with it at the moment.
Are you running in Cassini or are you running on IIS7?
I'm not sure if this may be the cause, but in your link tag, rel value should be "stylesheet", not "stylesheet/css".
Also, I don't use ASP MVC but don't you need a tag around the Url.Content, like so?
<%= Url.Content("~/Content/Site.less") %>
Have you tried setting the cache to false? On some machines I've had issues with it.
I am developing a Web app that is based on ASP.NET 3.5, and i added some page from ASP.NET MVC, everything is ok, until i use the "HTML" helper class, then the page is not being able be render, because this is not recognized.
For Example : Html.BeginForm() => this is not recognize as a method
But if i used "System.Web.Mvc.Html.FormExtensions.BeginForm", which is a extension method itself, it work fine.
Environment : ASP.NET MVC 2 and ASP.NET 3.5
Anyone experiencing this problem?
Thanks.
Do you have the System.Web.Mvc.Html namespace included in web.config's page assemblies list? I.e.:
<pages>
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
**<add namespace="System.Web.Mvc.Html" />**
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
I'm using Visual Studios' built-in ASP.NET Development Server (VWD) to test my web site during development.
I would like this ASP.NET web site to use extensionless URLs (pages don't require the aspx extension). Ordinarily I would configure a custom 404 in IIS that directs to an ASPX page. How would I do this with VWD?
P.S. This is not an ASP.NET MVC web site.
Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.
(full article here)
Note: this requires IIS7 as it is using the system.webServer section of the web.config.
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
<urlrewritingnet rewriteOnlyVirtualUrls="true"
contextItemsPrefix="QueryString"
xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!--Enable HTM(L) Extensions-->
<add name="pageHTML"
virtualUrl="^~/(.+).htm(.*)"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
<!--Fix the WebResource JS Error-->
<add name="WebResourceFix"
virtualUrl="^~/WebResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/WebResource.axd$1"
ignoreCase="true"/>
<!--Fix the ScriptResource JS Error-->
<add name="ScriptResource"
virtualUrl="^~/ScriptResource.axd(.*)"
rewriteUrlParameter="IncludeQueryStringForRewrite"
destinationUrl="~/ScriptResource.axd$1"
ignoreCase="true"/>
<!--Allow Extensionless Page Extensions-->
<add name="pageExtensionless"
virtualUrl="^~/(.+)$"
redirectMode="Permanent"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/$1.aspx"
ignoreCase="true" />
</rewrites>
</urlrewritingnet>
There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:
http://localhost:2181/Default
<%# Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello World
</div>
</form>
</body>
</html>
If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.
I posted some example code in a previous question.
All you need to do is add the module in two different places within your web.config...
<system.web>
<pages theme="Default" />
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRewriteModule"/>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7