I have a problem with LessAssetHandler which ships with BundleTransformer.Less library. I use LessAssetHandler in debug mode as a HttpHandler for transforming less files. Everything works fine except that the files inside ASP.NET areas are not handled by LessAssetHandler. For example file /Content/Style/page.less is handled by LessAssetHandler, byt for file /Areas/Admin/Content/Style/page.less this handler is not invoked. I have configured handler in the folling way:
<system.webServer>
<handlers>
<add name="LessAssetHandler" path="*.less" verb="GET" type="BundleTransformer.Less.HttpHandlers.LessAssetHandler, BundleTransformer.Less" resourceType="File" preCondition="" />
<handlers>
</system.webServer>
How can I force MVC to route less files from area through LessAssetHandler?
Registration of LessAssetHandler is correct. The exact same code is added to Web.config file during installation of NuGet package.
BundleTransformer.Less can work in ASP.NET MVC application with areas. It is possible, that you have incorrectly registered the bundle.
Bundle registration should look like the following:
var adminStylesBundle = new CustomStyleBundle("~/Bundles/AdminStyles");
adminStylesBundle.Include("~/Areas/Admin/Content/Style/page.less");
adminStylesBundle.Orderer = nullOrderer;
bundles.Add(adminStylesBundle);
Related
I am using asp.net core 3.1 and receiving values from URL. Its working fine but when I add "+" sign as a part of URL, it gives 404.
Example : localhost:9000/api/get/%2B12/values
+ is a special character. It should ideally be should be URL encoded as %2B.
Turns out it's not really required though (like in the screenshot below) but I still recommend it. (See: URL encoding the space character: + or %20?)
Here's a working example controller:
[ApiController]
public class ExpController : Controller
{
[Route("/api/exp/{arg}/values")]
public IActionResult Test(int arg) =>
Ok($"The arg is: {arg}");
}
Note how the route parameter is a int. For more complex values (other than just 12, +12, -12; eg: 12+12) the route will need to be a string instead.
version above IIS7 will refuse to request the URL contains symbols such as '+' by default. The following modifications are required. You need add the following nodes in web.config:
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true"/>
</security>
</system.webServer>
But now the .net core project does not have web.config to configure IIS options. You need to go to the location:
vs project location /.vs/config/applicationhost.config to add the above node.
Note that the .vs folder is a hidden folder and needs to be set visible.
Option 1 :
Mess with config to bypass request validation / allowDoubleEscaping (Asp.Net)
You need to be aware for certain risk/vulnabilirities described here:
https://stackoverflow.com/a/53621095/4798459
.netcore :
Since this issues is related to IIS, not your solution. You need to handle a web.config
Create a new web.config on the root of your project.
Right click, properties, set "Copy to Output Directory" to "Copy Always"
When you publish a .net core app, a "basic web.config" file is created. (For iis)
You need to copy the content of the "basic web.config".
You can find the auto-generated web.config file:
Where your app is already published (local server?)
You can also publish your api temporarly to a random path on your PC, see details here https://docs.devexpress.com/OfficeFileAPI/401445/dotnet-core-support/publish-net-core-application)
The web.config should like so, i added the tag with a a commentt
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<!-- XML node <security> is added to allow allowDoubleEscaping and add support for + paremeter in a route. Risk:https://stackoverflow.com/a/53621095/4798459 -->
<security>
<requestFiltering allowDoubleEscaping="true"></requestFiltering>
</security>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments="[.\SolutionName.Namespace.dll]" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Make sure that the step 2 is done before publishing your app otherwise it wont work.
Not tested with iisexpress
Option 2
Change pramater type in the api. Intead of being on the route, use a queryString instead
Option 3
Custom solution for request filtetring /routing, which i don't have any example, and seems a bit "over the top".
Option 4, to avoid:
Use an other solution for encoding / decoding special caracter (I have not tried)
https://stackoverflow.com/a/55637235/4798459
I have an host where I hosted a webpage with .cshtml extension. My host is arvixe.com that provides ASP and .NET hosting but when I try to load my web page I get this error message.
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /samples/WoT/Default.cshtml
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.276
I read something does I have to write something in my web.config file to make it work
like this
<compilation>
<assemblies>
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
<buildProviders>
<add extension=".cshtml" type="System.Web.WebPages.Razor.RazorBuildProvider, System.Web.WebPages.Razor"/>
</buildProviders>
</compilation>
But I tried everything, paste it in on different lines, nothing worked. What do I miss or do wrong?
I believe you are not making using the MVC feature and trying to load just the razor view outside views or custom Area folders.
Then you need to enable webpages key in Web.config which is disabled by default in .Net 4.0
<add key="webpages:Enabled" value="true" />
<appSettings>
<add key="webpages:Enabled" value="true" />
Repairing this in Windows 10 Pro using IIS 10 was a nightmare, it took two days but I was finally able to achieve the desired results using the following procedure:
Open your web site in Visual Studio. The way you do this is to go to File > New > Web Site and then select ASP.Net Empty Web Site AND before you click OK change the location to your project location. In my case I had my project in C:\inetpub\wwwroot\AspNet\Projects\Test
Open internet information services manager (click the "cortana" search and type IIS, it should show up as long as you have it installed). Locate your project folder under the ServerName > Sites > Default Web Site > ... , right click on it and click the "Convert to web Application" button. Accepting the defaults at the prompt by clicking OK should be sufficient in most cases.
Use the following Web.Config file, or something similar. NuGet may overwrite some settings but this isn't a big problem.
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301879
-->
<configuration>
<appSettings>
<add key="webPages:Version" value="3.0.0"/>
<add key="webpages:Enabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
</configuration>
Delete your bin folder, and packages.config file, if they exist. This is because we must assume that something in that bin folder is corrupt since IIS is designed to run Razor/ASP. In your visual studio project you will need to refresh your project so it knows these files have been deleted. This can be done by clicking the refresh button in the menu on the top of the Solution Explorer frame. In you visual studio project go to Tools > NuGet Package Manager > Package Manager Console and enter the following two commands.
Install-Package Microsoft.AspNet.Razor -Version 3.0.0
Install-Package Microsoft.AspNet.WebPages
This was enough to get *.cshtml pages to be rendered by IIS 10 on Windows 10 Pro.
I worked with the simile timeline a few years back and I am excited to see that it has moved into the .NET world. However, when I get it all set up and try doing the example on this site, I get an alert with this error:
"Failed to load data xml from /TimelineData.ashx?Dataid=4123ea6c-3c1b-482c-b8f6-24a9c2fe7465&type=rss
Not Found
It does load the timeline itself properly, but it doesn't load any dates from my codebehind or rss feed from the example. However, the test project worked as expected when I downloaded the latest source code. I didn't notice a file with the name TimelineData.ashx anywhere in the latest source code, and yet it ran fine. If I copy the cc1:Timeline directly from the Default.aspx file in the TimelineTest project, I get the same results, the above popup dialog error.
It kind of seems like support on their site has fallen off, I was just wondering if anyone out there is familiar with this control and could give me a hand?
I had the same problem.
The fix! IIS versions 7 and greater
put the handler in the system.webServer, NOT the system.web.
EDIT: formating.
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ashx" verb="GET" path="TimelineData.ashx"
Type="TimelineNet.TimelineAjaxHandler, TimelineNet"/>
</handlers>
</system.webServer>
Its seems that you did not have setup the web.config to accrept the ashx for time line
Read this page for details
http://timelinenet.codeplex.com/wikipage?title=Installation&referringTitle=Home
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path=".ashx" type="TimelineNet.TimelineAjaxHandler, TimelineNet" validate="false" />
</httpHandlers>
</system.web>
</configuration>
UPDATE:
In Windsor 2.5 the assembly name is Castle.Windsor not Castle.MicroKernel
I'm trying to deploy an ASP.NET MVC app to IIS7 and I'm getting this error:
Looks like you forgot to register the http module
Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule Add '' to the section on your
web.config
My httpModules contains:
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel"/>
</httpModules>
system.webServer handlers section contains
<handlers>
<remove name="PerRequestLifestyle"/>
<add name="PerRequestLifestyle" preCondition="managedHandler" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Microkernel" verb="*" path="*.castle" />
</handlers>
I added the verb="*" path="*.castle" part as I was getting errors when they were missing. Not sure if their values are correct.
Anyone know what the problem is here?
You can solve the problem by registering the HTTP module in configuration/system.webServer/modules instead of configuration/system.web/httpModules.
My problem was that I was bootstraping the container in Application_Start, Modules are not initialized at that point in ASP.NET so when you try to register/use PerWebRequest Lifestyle it throws that Exception because it detects that the module was not initialized.
I ended up using this library from Castle Contrib which provides the HybridPerWebRequestTransient Lifestyle which if not initialized at the moment uses the Transient Lifestyle.
You just have to download the library (as zip is ok) open the Solution and compile it, grab the generated DLL and reference it in your project.
If you are using Castle.Windsor version over 3.0 you will have to remove current reference to it and add the reference to the version you are using (I was using 3.1 and did not have any problems).
This is the code to use the Lifestyle: .LifeStyle.HybridPerWebRequestTransient()
Took me some time to find a solution for this but all I had to was update the dll being referneced in the web.config...
Using Castle.Core and Windsor 2.5.1...
I'm trying to map requests for classic asp pages to be handled by .net, so that it runs through a custom httpmodule.
In IIS I have remapped asp requests to aspnet_isapi.dll - I'm sure I've done this bit right
Now in my test app I am getting this error:
Server Error in '/TestASPRedirect' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /testaspredirect/test.asp
Searching online for this error shows a load of people having problems with cassini, but this is not really relevant, I am testing this on both IIS 5.1 on XP dev machine, and have tested on IIS6 also getting the same error.
I have followed instructions for adding and registering a httphandler (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308001), but I don't know what to put in the ProcessRequest routine to ensure the request gets passed on. What is the default .net httphandler, can I just map to this in web.config?: so something like:
<httpHandlers>
<add verb="*" path="*.asp" type="standard.nethttphandler"/>
</httpHandlers>
How do I tell asp.net that it needs to pass ASP requests on and not block?
Actually you are only one step far from the success. Adding following section to your Local website(or virtual directory) web.config file:
<configuration>
...
<system.web>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
</httpHandlers>
</system.web>
It looks like the .asp extension is mapped to the HttpForbiddenHandler.
If you're using ASP.NET 1.1 then open the following file:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
If you're using ASP.NET 2.0 then open this file:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
Search for "path="*.asp"", then comment out that line. It'll like something like:
<!-- machine.config/ASP.NET 1.1-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler"/>`
<!-- web.config/ASP.NET 2.0-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler" validate="true"/>`
Locate the below file:
C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<FramworkVersion>\Config\web.config
where <FramworkVersion> is folder name:
open it in an XML editor .. (even notepad is fine)
and add below line :
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
under below XPath:
configuration/system.web/httpHandlers
replace the existing one!
Add below line:
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
under below XPath:
/configuration/system.web/compilation/buildProviders
Worked like gem for me :)