Sorry if this has been asked before, but I couldn't find a solution to this problem.
My route is defined as a/{param1}/{param2}/{param3}/{param4}/{param5}.
Everything works when the parameters are simply words, but when any of the parameter look like someword%2bsomeotherword, everything breaks and the route isn't matched. If I remove the %2b, then the route is resolved.
This is the first route registered, so I don't think it's finding a better route first.
Sorry if this is answered somewhere, but I have gone through a bunch of SO answers and other links. Routes in MVC have always eluded me.
Thank you for any help.
The issue is IIS here, not the solution itself / code.
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
Asp.net :
use web.config directly in solution add this: Credit: https://stackoverflow.com/a/6026291/4798459
<system.web>
<httpRuntime requestPathInvalidCharacters="" requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
.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
Related
I have a site on IIS server which hosts ASP.NET REST APIs. They work on separate application pools which all have Unmanaged Code as their .NET CLR version. All .NET Core APIs .NET Core 3.1 written.
I have also installed hosting bundle, SDK, ASp.NET And Desktop SDKs as shown below.
Unfortunately the app does not work. When I investigate it seems the error is IIS/configuration related. The application I have deployed is published as follows :
And the web.config is as follows :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<!-- The line below -->
<aspNetCore processPath=".\Unity.REST.API.WM.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
With this configuration, when I try to open Configuration Manager of the site under Management tab I get the following error.
However if I remove the line under the "The line below" comment, I can view configuration, but I certainly need to keep that line to make my .NET Core REST API working.
I have copied all the files and config from another server and it works OK there. Is there any possible solution you can suggest?
In applicationhost.config, check if you have such an entry:
<section name="aspNetCore" overrideModeDefault="Allow" />
Believe it should be under <configuration> -> <configSections> -> <sectionGroup name="system.webServer">
If you don't have it, try adding it and restart IIS.
This problem occurs because the ApplicationHost.config or Web.config file contains a malformed or unidentified XML element. IIS can't identify the XML elements of the modules that are not installed. You can find probloem element by commenting some blocks and looking for type of error.
And you can also try to check whether URL rewrite is installed.
https://www.iis.net/downloads/microsoft/url-rewrite.
I get this error while trying to initiate a project in ASP. I have already added
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
To the Web.config but I still get this error. Also, I have tried initiating the IIS Express by opening appcmd.exe but this did not fix it either. None of the solutions I have found worked for me so far.
Any ideas?.
Step 1. Open IIS
Step 2. Go to the WebSite you are facing issue with.
Step 3. Click on Default Document Button, you will find it on the right side tab in IIS.
Step 4. You can see a list of default documents, but your default page (aspx file) is not mentioned here and that is causing the issue.
Add your file here. (For example: Index.aspx)
You can also add the following entry into the web.config:
<system.webServer>
<defaultDocument>
<files>
<add value="Index.aspx" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
</system.webServer>
Hope it helps.
I updated my ASP.NET Core project from RC1 to 1.0 RTM (with preview2 tooling), everything went fine. I can debug in Visual Studio without problems. Next I would like to upload the site on a Windows Server 2008 R2 and IIS 7.5. I installed the necessary Windows Hosting tools and created the web application in the IIS. The problem is, that after I tried to open the page, it returned a 404 error. As I see in the task manager, my application is running, but stops in listening mode.
In the log file I only see these entries:
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\MySite
Now listening on: http://localhost:20706
Application started. Press Ctrl+C to shut down.
It seems like there is some problem with the IIS integration. My web.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="..\..\approot\MySite\MySite.exe" arguments="" forwardWindowsAuthToken="true" stdoutLogEnabled="true" />
<httpErrors errorMode="Detailed" />
</system.webServer>
</configuration>
I tried some workarounds from GitHub, which affected the Startup.cs file's Configure method without any success.
Any ideas?
FYI.. This web.config file was missing in the app folder.
This file should be at: C:\wwwwroot\myapp\
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\XXX.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
Don't forget to replace XXX.exe with the correct name of your Web API exe name.
Ok, I had multiple problems, but the two main reasons why my site didn't work:
I cannot start the code from two separate places. I originally put the wwwroot content under the wwwroot folder (not so suprising), and the rest to the approot. Now everything should be in the same folder.
My release versions didn't want to work. I must use the contents of the debug folder. I don't know why.
And now, everything is ok.
please click on .cshtml file in Views folder and set build action=Content in right bottom panel in Visual Studio. My problem has been solved
I have a content management application in the root of my website, and I'm trying to use a different app (a billing application) under a sub-folder. Unfortunately, the web.config of the root site is interfering with the sub-app.
Is there a way to just disable web.config inheritance for a sub-folder?
Update:
As linked by Stephen Burris, using the <location> tag can prevent inheritance for part of the web config, as follows:
<?xml version="1.0"?>
<configuration>
<configSections>
....
</configSections>
<location path="." inheritInChildApplications="false">
<appSettings>
....
</appSettings>
<connectionStrings/>
<system.web>
....
</system.web>
<system.codedom>
....
</system.codedom>
<system.webServer>
....
</system.webServer>
</location>
<runtime>
....
</runtime>
</configuration>
The <configSections> and <runtime> sections will not accept being enclosed in the tag...so I guess this only does most of the job. Anybody know how to do it better?
There is an attribute that you can use in the root web.config file to cause it not to have its contents become inherited by child applications.
inheritInChildApplications
Blog about inheritInChildApplications
MSDN article on ASP.NET Configuration File Hierarcy and Inheritance
Put the part of the config that is not for inheritance inside
<location inheritInChildApplications="false">
<NotInheritedConfigPart/>
</location>
Config sections seem to be impossible to not inherit, but other parts of configuration can be "commented" out like this and don't get inherited.
If you can use 2 separate application pools, you can completely stop inheritance by using an attibute enableConfigurationOverride="false" in the applicationHost.config file as I described in this question: “Entry has already been added” - Two Separate App Pools
<add name="MyAppPool" enableConfigurationOverride="false" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" >
<processModel identityType="NetworkService" />
</add>
In my opinion every time I've struggled with this the answer ends up being effectively NO - and I'm leaving this here for my future self to find so he doesn't waste any more time on it.
I've found this to be a huge problem when you just want to add something as a virtual directory inside an existing site. With a complex web.config files I've always just ended up giving up and moving it to a different application altogether.
I would explicitly define all of the settings required - never assume that any setting is still set to the default value.
For example, if you're defining a connectionString include a <clear /> tag before the <add name=... />, etc. For Membership define all of the attributes, including the cookie name. And so on.
It may make the file a bit bigger but it will definitely help you avoid the "but it worked on my box" scenario too :-)
I have faced this situation a few times. It seems that the parent poster's instincts are in the ball park. I have found that adding two entries seem to have solved it—both a <location> entry.
Find your <system.web>…</system.web>. Wrap it with a <location path="." inheritInChildApplications="false">.
Now check the parent site and make sure it still works.
Check the child: does it work or give an error?
If you still have an error, do the same thing with <system.webserver>; wrap the same <location> tag around it.
In summary - in the PARENT:
<location path="." inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>
and maybe:
<location path="." inheritInChildApplications="false">
<system.webserver>
...
</system.webserver>
</location>
i am pretty new to MVC and Routing and i was asked to modify an app to use diffrent url's.
a task that is a bit over me since i have no experience.
ok, lets talk a bit of code:
routes.MapRoute(
"CategoryBySeName", // Route name
"products/{SeName}", // URL with parameters
new { controller = "Catalog", action = "CategoryBySeName" }
);
this works as expected, but then the client wanted ".html" at the end of paths, so i changed:
"products/{SeName}", // URL with parameters
to:
"products/{SeName}.html", // URL with parameters
which fails ( IIS 404 page - MapRequestHandler)
it seems like iis is trying to load a physical file with that name instead of passing it to the application.
Similar: ASP.NET MVC Routing to start at html page (not answered, Not duplicate)
You have to force all request through the ASP.NET pipeline, and you can do that by adding only this single line to the web.config of your application:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
You're guess that an IIS handler is probably grabbing the request prior to MVC is likely correct.
Assuming IIS 7:
http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx
You need to edit the .html handler in IIS to use ASP.NET.
You can find it in the website properties under the home directory tab in app configuration in the mappings section in II6.
Something along the lines of (version may be different):
C:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll is what you need to handle the .html files.
Changing the Application Pool from Classic to Integrated fixed the issue.
thank you guyz for your help.
Just add this section to Web.config, and all requests to the route/{*pathInfo} will be handled by the specified handler, even when there are dots in pathInfo. (taken from ServiceStack MVC Host Web.config example and this answer https://stackoverflow.com/a/12151501/801189)
<location path="route">
<system.web>
<httpHandlers>
<add path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" />
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="ApiURIs-ISAPI-Integrated-4.0" path="*" type="System.Web.Handlers.TransferRequestHandler" verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
</location>