asp mvc IIS7 less/sass empty file - asp.net-mvc

I'm trying to use less in my new project. I've installed dotLess and System.Web.Optimization.Less packeges (as described in Yet Another "Add LESS to your ASP.NET MVC Project" Post) and locally everything works fine. But when I publish project IIS7 server responds with empty css file /Content/Main/site?v=
Here is my web.config
...
<configSections>
<section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
</configSections>
<system.web>
<httpHandlers>
<add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="dotless" path="*.LESS" verb="*" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition=""/>
</handlers>
</system.webServer>
<dotless minifyCss="false" cache="true" web="false" />
And my BundleConfig.cs
bundles.Add(new LessBundle("~/Content/Main/site").Include("~/Content/Main/Site.less"));
When I append css extension to my Site.less file (Site.less.css) server responds with content (/Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41) but it still pure less with all its variables and etc.
The same with Bundle Transformer: Sass and SCSS
What have I missed?

As you are getting
/Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41
then this means that the bundling is working correctly. Therefore there is probably something in Site.less that is causing the problem. One thing to watch out for is relative urls. For example if you have an image in your css
.bacon {
background-image: url(bacon.png);
}
The bundle will look for this with ~/Content/Main taken from the name of the bundle. (/site is fine and can be anything, it's just the name of the bundle)
The first thing to try is take out any imports, images etc and see if it bundles correctly. You can do this on your local dev build by enabling optimizations in the your bundle config.
BundleTable.EnableOptimizations = true

Another way to solve this is to remove dependency on System.Web.Optimization.Less and dotLess and use free Visual Studio Extension https://github.com/madskristensen/WebCompiler for precompilation of less to css (with and without minification).

Related

Issues on configuring IIS for mvc asp .net 3.1 application

I have problems with hosting web app on IIS. In next photos you will see my configuration files that I change and errors that I have when try start app on browser.
web.config:
<configuration>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\bin\Debug\netcoreapp3.1\TaskTracker.Frontend.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess" />
</system.webServer>
</configuration>
hosts file
applicationHost
applicationHost part 2
Error when I try to see authentication of app
I was setup permissions on app folder in properties-security of foler.
When I try to consume app through browser, error was:
server error in browser
There is a problem with your web.config file configuration, I suggest you reinstall IIS and ASP.Net Core module to restore the configuration files.

Cannot run Glimpse with ASP.NET MVC 5 Application on IIS

I have an ASP.NET MVC 5 application that is running on IIS and I want to use the Glimpse Package so that I can monitor all of the SQL calls that are being made within my application.
I have installed Glimpse using the Nuget Package Manager Console by using the command:
Install-Package Glimpse.MVC5
Since my application is running on IIS, I added the following commands to my web.config file:
<configuration>
<configSections>
<section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
</configSections>
</configuration>
<system.web>
<httpModules>
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet"/>
</httpModules>
<httpHandlers>
<add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet"/>
</httpHandlers>
</system.web>
<system.webServer>
<modules>
<add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode"/>
</modules>
<handlers>
<add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
</handlers>
</system.webServer>
After these commands are in place and I try running my application through IIS, I get the following error:
Could not load file or assembly 'Glimpse.AspNet' or one of its dependencies. The system cannot find the file specified.
I know that Glimpse is really set up to work by building your application locally but I think you can get it to work on a remote server as well.
Any help would be greatly appreciated!
I eventually got Glimpse up and running by making sure I installed all of the necessary NuGet packages for it.

Javascript bundling in another folder

How can I have JavaScript bundling working from another folder (aside from the Script folder). If I do this:
bundles.Add(new ScriptBundle("~/bundles/search").Include("~/Views/Search/*.js"));
The browser tells me the javascript file can't be found. Is it possible to do this
or do all my sripts have to be in the Scripts folder?
Basically I want my Javascript included in my View subfolders
You need to change web.config in Views folder according this answer:
In ASP.NET MVC, how can I load script from my view folder?
Good example from Ashley Lee:
<system.webServer>
<handlers>
<add name="JavascriptViewHandler" path="*.js" verb="*"
preCondition="integratedMode" type="System.Web.StaticFileHandler" />
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
Since you specifically want to only include javascript files, make the following change to your ~/Views/web.config file, by adding the "JavascriptViewHandler" section.
<system.webServer>
<handlers>
<add name="JavascriptViewHandler" path="*.js" verb="*"
preCondition="integratedMode" type="System.Web.StaticFileHandler" />
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*"
preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
This will preserve all of the current blocking for non-javascript files.
I don't know if i understood your question properly, but if you want to use a script file from any folder in a View or preferably in it's Layout, you can add the following tag in <head> section of you View or _Layout.cshtml:
<script src="#Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>
You can mention the complete path to your script file instead of ~/Scripts/jquery-ui.min.js

Adding HttpHandler to MVC application

I have an MVC4 application to which I added an HttpHandler:
<system.web>
...
<httpHandlers>
<add path="Files" verb="*" type="MyHttpHandler" />
</httpHandlers>
</system.web>
I also ignored the relevant path in RegisterRoutes so that the requests to "Files" are not handled by MVC:
routes.IgnoreRoute("Files/{*pathInfo}");
The problem is that the MyHttpHandler is invoked only for requests to "Files", not for any of its children or sub-folders.
I've tried using the <location> element, but getting that to work means that you will be hard coding the application's virtual path in the "path" attribute (e.g., <location path='MyApp\Files'>).
What is the correct method to use to allow all requests for "Files" and any of its sub-folders (and sub-folders of those folder, etc) to get routed to MyHttpHandler?
Scratch that...<location> seems to work OK. Though, you need both the <web> and <webServer> entries to ensure that it works for both IIS and the Visual Studio Development Server. For example:
<location path="Files">`
<system.webServer>
<handlers>
<add name="MyHandler" path="*" verb="*" type="MyHttpHandler" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="MyHttpHandler" />
</httpHandlers>
</system.web>
</location>

ASP.Net MVC 3/4 Hosted on IIS 7.5 Default Handler Mappings

What are the correct Default Handler Mappings for ASP.Net, ASP.Net MVC and WCF Services hosted on IIS 7.5 .Net Framework 4.0 on Windows 7 (PRO)?
Out of a team of 8 developers who installed ASP.Net MVC 3/4 only 1 developer could get a basic ASP.Net MVC 3 Internet application to work under the Default Web Site in IIS 7.5 without changing the Handler Mappings, none of the team could get a second Website with the same site to work with the site sirectory located in a sub directory of the root website. inetpub/wwwroot/site
Below are three of the Handler Mappings set in IIS 7.5 all are different and have not been changed by the developers.
What is the best way to define the required settings as Defaults and ensure all workstations have the same configurations applied without setting them in the Website Web.Config file?
I successfully deployed MVC 4 to my local IIS 7.5 (windows 7). This fix my problem (as mentioned here)
(For x64 system)
%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i
(or if you in 32-bit system)
%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
Also, I changed the DefaultAppPool to use v4-Integrated (from v2-Classic), converted the website to application, and have the application to use DefaultAppPool.
Here is my complete Web.config. It has Handler included.
<?xml version="1.0" encoding="utf-8"?>
<compilation targetFramework="4.0" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
Assuming that your default website has been configured as an application in IIS, the most likely cause of this issue is having the application pool running the Classic pipeline as opposed to the Integrated pipeline. In all of the MVC applications that we have deployed to Azure, local IIS servers and development machines, we have not had to touch the handler mappings unless having to trick IIS 6 into hosting an MVC site.
To check for the application pool pipeline:
Open the IIS manager
Right click on the Default Web Site, and choose Advanced Settings. This will open up a window
Note the name of the Application Pool. Now, close this window and click on Application Pools on the left hand menu in IIS manager
If the Managed Pipeline Mode is not set to Integrated (eg is reading classic), then right click the Application Pool and select basic settings. From here, you can change the Pipeline type. Choose integrated.
5.The application pool should immediately restart, but you can choose to restart it or IIS manually to ensure that your changes have taken affect.
Note - If you are running IIS 6, here is a link that describes how to adjust the handler mappings so that IIS 6 can run an MVC site.
Addendum - If you have been mucking with the handler mappings, depending on what has been changed, you may want to try this on a clean IIS install. It is not clear what handlers have been misconfigured as your team attempted to make an MVC deployment work.

Resources