IIS bundles/less cache issue - asp.net

I have an ASP.NET MVC 5 project that uses dotless for parsing/compiling .less files and standard bundler for minifying/bundling js files.
The issue is that on production server cache-conrole header is set to max-age=0, no-cache, no-store when locally on IIS express it's set to public and expires in a year.
Dotless config: <dotless minifyCss="true" cache="true" web="true" handleWebCompression="false" />
Bundle config - just includes and BundleTable.EnableOptimizations = true;
Few web config sections that may help:
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
...
<modules runAllManagedModulesForAllRequests="true">
<add name="Prerender" type="Prerender.io.PrerenderModule, Prerender.io, Version=1.0.0.2, Culture=neutral, PublicKeyToken=null"/>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate32" />
</modules>
...
<handlers>
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
I tried to add mime maps to staticContent section. Also thought about adding request headers in iis, but it works only for files/folders so it likely will not serve bundle.
What have I missed in configs? I appreciate any idea for fixing the issue.

Check if you got in your web.config that stuff:
<configuration>
<system.web>
<compilation debug="false"/>

Related

IIS 10.0 Detailed Error: mimeMap

Hello so I'm pretty new to using IIS and Visual Studio but I've managed to launch one website on IIS but when I try to launch this one I get this error across the page:
Error message:
Cannot add duplicate collection entry of type 'mimeMap' with unique key attribute 'fileExtension' set to '.mp4'
There's a section that reads Config Error:so here is my web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="DetailLogging" value="True"/>
<add key="LoggingConfigFile" value="log4net.config"/>
<add key="DatabaseConnectionString" value="Integrated Security=True; MultipleActiveResultSets=True; Data source=.\SQLEXPRESS; Initial Catalog=WebEvaluation" />
<add key="Email" value="***********************"/>
<add key="SupportEmailID" value="*************************"/>
<add key="ForgotPasswordEmailSubject" value="Butterfly Scheme e-Certification Admin Console - Password Request"/>
<add key="WelcomeMailSubject" value="Butterfly Scheme e-Certification Admin Console"/>
<add key="PasswordChangedMailSubject" value="Butterfly Scheme e-Certification Admin Console - Password Changed"/>
<add key="PasscodeDeleteMailSubject" value="Passcode delete notification - "/>
<add key="Host" value="***********"/>
<add key="PortNo" value="25"/>
<add key="Password" value="***********"/>
<add key="SiteURL" value="***********************************"/>
<add key="RecordsPerPage" value="20" />
<add key="PasscodeCreateMailSubject" value="Butterfly Scheme e-Certification Passcode List created for : "/>
<add key ="XlsConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties='Excel 8.0;IMEX=1'"/>
<add key ="XlsxConnectionString" value="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 8.0;'"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=******************"/>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=******************"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpRuntime requestValidationMode="2.0" maxRequestLength="2097151"
executionTimeout="900"/>
<sessionState mode="InProc" timeout="20"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<staticContent>
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
<mimeMap fileExtension=".m4v" mimeType="video/m4v"/>
<mimeMap fileExtension=".3gp" mimeType="video/3gpp"/>
</staticContent>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147482624"/>
</requestFiltering>
</security>
</system.webServer>
</configuration>
You could add something like this:
<remove fileExtension=".mp4" />
Or, since the MP4 mime type seems to be already present in the roots configuration file, simply omit the whole line:
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
If you really want to be sure that the extensions you seem to require are present, this could be a replacement for the staticContent tag:
<staticContent>
<remove fileExtension=".mp4" />
<remove fileExtension=".m4v" />
<remove fileExtension=".3gp" />
<mimeMap fileExtension=".mp4" mimeType="video/mp4"/>
<mimeMap fileExtension=".m4v" mimeType="video/m4v"/>
<mimeMap fileExtension=".3gp" mimeType="video/3gpp"/>
</staticContent>
Could not load type "PresentationLayer.Global"
Check if you namespace is PresentationLayer or is changed? If changed update it in the markup, by right clicking on Global.asax and select "View Markup"

Default landing page asp.net web api published IIS

I have created a .Net project 4.6 using web api.
just for simplicity purpose, I created default.htm in the parent directory. I publish my project to localhost, and set up the default document to default.htm as per the screenshot:
published web.config:
<system.web>
<authentication mode="None" />
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.5.2" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
However, whenever I navigate to http://localhost/, it always returns 404 as per the screenshot below: Can someone please help? Thanks
I am using port 80:
All published Web Site in IIS need to have a port like this:
1.Assuming you are using the port of 8462.
2.Try to navigate this url = localhost:8462
Make sure your asp.net has been registered to your IIS like this aspnet_regiis -i
Good Luck!

HTTP Error 500.23 after adding dotless to my local website

Hi I'm trying to run dotless on my local .net4 web site
My web config looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers><add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" /></httpHandlers></system.web>
<dotless minifyCss="false" cache="true" web="false" />
<system.webServer>
<handlers>
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
</system.webServer>
</configuration>
Here is the error I get
HTTP Error 500.23 - Internal Server Error
An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
Most likely causes:
This application defines configuration in the system.web/httpHandlers section.
Can you please help?
adding <validation validateIntegratedModeConfiguration="false"/> worked
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpHandlers>
<add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
</system.web>
<dotless minifyCss="false" cache="true" web="false" />
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
</system.webServer>
</configuration>
<validation validateIntegratedModeConfiguration="false"/> tells IIS to ignore configuration issues. One such issue seems to be the fact that dotless automatically adds a handler to system.web and system.webServer. The former section is used by the classic application pool mode, whereas the latter by the new integrated application pool mode. Since I am using the integrated mode, removing the handler in system.web helped just as well.
I had to add <validation validateIntegratedModeConfiguration="false"/> to my webserver section and I also had to move the configSections to be the first element in my Configuration.
<configuration>
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
We will add a small piece of code into web.config file. open web.config from your IIS root or change the setting in Visual Studio web.config and publish again.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>

UrlRewriting.Net not working even with a simple rewrite

I want to make URL rewriting using UrlRewriteNet module.
While I have added all the required config settings, nothing seems to take action even for simple rewrite.
web.config:
<configuration>
<configSections>
<!-- URL Rewriting.NET -->
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.web>
<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>
<urlrewritingnet
xmlns="http://www.urlrewriting.net/schema/config/2006/07">
<rewrites>
<add name="GeneralRewrite"
virtualUrl="^~/Default.aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/MyDefault.aspx"
ignoreCase="true"
/>
</rewrites>
</urlrewritingnet>
</configuration>
Nothing more is requires as far as I understand to just rewrite the Deafault.aspx page to MyDefault.aspx. So I would expect my URL from https://server.address/Project.SiteName/Default.aspx to simply become https://server.address/Project.SiteName/MyDefault.aspx.
I use development in my local IIS 7 Windows 7 development pc but the release production server will be IIS 6 thats why I included both configuration into the web.config.
Unfortunately, and where there is no error for any reason, checked the IIS and saw that the module is registered in Modules section but the engine never runs !
Is there something that I miss here?
make the above in following manner
<configuration>
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission ="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection,
UrlRewritingNet.UrlRewriter" />
</configSections>
</configuration>
then comes the rewriting sections to rewrite urls
<urlrewritingnet>
<rewrites>
your urls to rewite will mapped here.....
</rewrites>
</urlrewritingnet>
and finally need to http module which will listen to the requests.
<system.web>
<httpModules>
<add name="UrlRewriteModule"
type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
Except this no configuration needs to done in web.config just reference the dll (mandatory)
and .xsd file for intellisense
http://blog.vizioz.com/2009/11/add-intellisense-when-using-url.html
Open Web.config and add modules
<configuration>
<system.webserver>
<modules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
</system.webServer>
</configuration>

Unable to map an HttpHandler to a "path/*" wildcard mapping

So I've been trying to map an http module to a sub-path of an MVC3 site. It should be pretty simple as I understand it, but it has not been working. The module is setup like so:
<handlers>
<add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</handlers>
A matching section is also there for iis6 so I can run it under webdev.webserver. However testing both deploying to my local iis7 (under Win7) and with webdev.webserver, only /api actually calls the handler. If I call /api/{anything} it just returns a 404.
I'm sure I'm just "doing it wrong (tm)" but any help would be appreciated.
Note: I've also tried a couple other configurations including using a tag and creating a /api folder and adding a web.config to that folder with a full wildcard.
Simple. Just put the path, no wildcard.
<handlers>
<add name="Nancy" path="api" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</handlers>
This will match:
/api/{anything}
The URLRoutingModule-4.0 is a catch all handler listed before your nancy handler. It will thus come into play before your handler is ever hit. You can remove the handlers add yours and add them back in like so:
<handlers>
<remove name="BlockViewHandler" />
<remove name="UrlRoutingModule-4.0" />
<add verb="*" path="robots.txt" name="robots" type="System.Web.StaticFileHandler"/>
... custom handlers here
<add name="Nancy" path="api/*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
... now add back UrlRoutingModule and BlockViewHandler
<add path="*" verb="*" name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" preCondition="managedHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
You can see the handler order in IIS7 under Handler Mappings select View Ordered List and it will list the order in which it loads the handlers top (first) to bottom (last).
You might need a second Web.config in your /api folder
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<clear />
<add name="Nancy" path="*" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" allowPathInfo="true" />
</httpHandlers>
</system.web>
</configuration>
Similarly, this is what I usually do for "/static" content on websites. I have not found out how to circumvent the need for the seconds web.config.
EDIT
I had a hard time figuring this out when i had to as well and it seems my memory hasnt served me well. I dont specify a path/* handler anywhere instead I have this:
(only specifying simple wildcards/fully qualified paths to go around UrlRouting)
<location path="." inheritInChildApplications="false">
<system.webServer>
<!--
ml: in .NET 4.0 its now safe to remove from the modules section.
Make sure you have a *. mapping to a ExtensionLessUrl hanlder in IIS
this should improve performance a tad albeit neglectable.
see: http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static-requests.aspx
-->
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="false" />
<handlers>
<remove name="BlockViewHandler" />
<remove name="UrlRoutingModule-4.0" />
<add verb="*" path="robots.txt" name="robots" type="System.Web.StaticFileHandler"/>
.. Some company handlers i can't list
<add path="*" verb="*" name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" preCondition="managedHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</location>
Then in my /Content/web.config file I set the following:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<clear />
<add name="StaticFiles" path="*" verb="*" modules="StaticFileModule" resourceType="Either" requireAccess="None" />
</handlers>
<staticContent>
<clientCache cacheControlMaxAge ="31.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>
</system.webServer>
</configuration>
My handler list for /Content/ looks like this now:
Which is about as sure as I can be anything in /Content/ will be served through StaticFileModule. The trick here seems to be specifying: inheritInChildApplications="false".
Seems the UrlRoutingModule-4.0 is more trouble than it is worth. Instead I've just told MVC3 to ignore the routes. Not a perfect solution but until I have something that works better I'll have to stick with this in RegisterRoutes:
routes.IgnoreRoute("api/{*route}");

Resources