validateRequest and requestValidationMode dont work with .net 2.0 - web-config

I am hosting WCF Service in IIS 7. They are running under .net version 2.0. Everything is working fine. But lately, i am getting error list "Potentially Dangerous request ...". I searched on the internet and found out have i have to set my web.config like this.
<system.web>
<httpRuntime requestValidationMode="2.0" />
<pages validateRequest="false" />
</system.web>
I updated my web.config but then I am not able to browse to the services. It is giving me this error.
Parser Error Message: Unrecognized attribute 'requestValidationMode'. Note that attribute names are case-sensitive.
Please help me to resolve this error.
Thanks,
Vivek

The requestValidationMode attribute was introduced in .NET 4.0.
Under .NET 2.0 you should only have to add <pages validateRequest="false" /> to your Web.config to avoid Potentially Dangerous request errors.
You can also turn request validation off for an individual page using <%# Page ValidateRequest="false" %>.

If you find requestValidationMode="2.0" in your web.config, it is very likely that the developer has been targeting against framework 4.0 or higher and you should probably set the application pool to the corresponding version, rather than change the settings.

Related

Something wrong with my web.config file while hosting web service

To give some context:
I'm trying to deploy a webservice I built, within visual studio you have the option to use 'Folder Deployment', I am using this option and that deployment allows me to make a build within a folder that has an executable which works like a charm when I'm using it on localhost but because my webservice needs to be used through a network, I need to deploy it to IIS which gives me some challenges.
I'm trying to host my RESTful API web service on the IIS server as explained in this article: https://www.c-sharpcorner.com/article/publishing-asp-net-web-api-rest-service-using-file-system-method/ but every time I add it to the server, and try surfing to the site I get the following error page: HTTP Error 500.19 - Internal Server Error --> 0x8007000d which apparantly tells me that something is wrong with my web.config file but I never touched that during my development..... perhaps you guys see something odd as here is my web.config file:
<?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="dotnet" arguments=".\Flame_webservice.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 21d59c04-6877-4549-9ff7-c37f07155f97-->
After searching for solutions I already found several articles that suggested installing things but it doesn't seem to do the trick for me, the following article I have tried:
Web Application Problems (web.config errors) HTTP 500.19 with IIS7.5 and ASP.NET v2
I don't think I'm using AJAX but maybe I am so I haven't tried that yet.
My webservice contains 3 controllers which are essentially websites but I don't see an explicit route to the websites in the web.config file, I'm not sure if that can cause issues?
I will continue searching but it's becoming a pretty rough ride at the moment due to my limited experience with hosting web services. Or am I perhaps using IIS while I shouldn't? I mean I've tried turning off my firewall and reaching the executable running on localhost through my IP address but it doesn't seem to work which led me to believe I needed a server to reach the running web service on my local machine.
I had the same exact issue and what helped was:
installing .net core windows hosting on the server.
Install-Package Microsoft.Extensions.Hosting -Version 3.1.10

Why do we need web.config in ASP .NET 5 wwwroot?

In ASP .NET 5, Configuration is changing drastically. We no longer have a web.config file. Instead, we can use JSON and other options, depending on how we set things up in our Startup class. Unlike web.config, such configuration typically doesn't go in wwwroot, and there is no danger that clients can gain access to it.
And yet, in the ASP .NET 5 project templates there's a web.config file in wwwroot with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
</system.webServer>
</configuration>
It seems to me that this could be something that the hosting server is looking for at runtime, independently of the application configuration.
Can anyone shed some light on why this is needed, and how it works?
Web.config is strictly for IIS Configuration. It is not needed unless hosting in IIS. It is not used when you run the app from the command line.
In the past Web.config was used for both IIS configuration and application configuration and settings. But in asp.net 5 it is not used by the application at all, it is only used for IIS configuration.
This decoupling of the application from IIS is part of what makes cross platform possible.

EntityFramework deployment with AppHarbor

I am running into a strange problem after deploying my site to AppHarbor.
I always get this error :
Exception Details: System.Data.MetadataException: Schema specified is not valid
It is clearly linked with my connection string (which works perfectly on my dev machine)
<add name="DbEntities" connectionString="metadata=res://*/Models.DbModel.csdl|res://*/Models.DbModel.ssdl|res://*/Models.DbModel.msl;provider=System.Data.SqlClient;provider connection string="Server=xxx.sqlserver.sequelizer.com;Database=xxx;User ID=xxx;Password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I dont use EF code first so I cannot remove the metadata section.
Any idea what to do to fix it ? I couldnt find anything to help me get over this...
For Info I am using VS 2012, .Net 4.0, EF 4.4
The AppHarbor knowledge base has info on using the SQL Server add-on, including setting the metadata-string: http://support.appharbor.com/kb/add-ons/using-sequelizer

ASP.NET MVC on IIS falls through to the static file handler

I have a problem with an ASP.NET MVC site.
These are the details:
ASP.NET MVC 2
ASP.NET 4 integrated pipeline
IIS 7.5 on Windows Web Server 2008 R2
Whenever I make a request for the app I get the "HTTP Error 404.0 - Not Found"-error and the detailed error information shows it is the static file handler that reports the error:
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
meaning that the request never entered the MVC stack.
I should note that the IIS already serves a ASP.NET MVC 3 on the same app pool and a MVC 2 on a ASP.ENT 2 app pool. So it's the combo ASP.NET 2 on the ASP.NET 4 app pool that are giving me headaches.
Basically I want to upgrade the app from ASP.NET MVC 2 on a ASP.NET 2.0 app pool to a ASP.NET MVC 2 on a ASP.NET 4.0 app pool.
So any ideas?
I see you fixed your issue, but for anyone googling:
I had this issue and in my case I just needed to register ASP.NET 4 with IIS. I was deleting and re-adding webs to fix other issues and simply forgot to do that. The command that worked for me was:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis -i
Your own .net version may be different, especially if you are in the future, so the above path may not be exactly right.
I had the same problem when I installed IIS after installing Visual Studio, etc.
I was able to fix the problem by changing my Web.config file, adding the runAllManagedModulesForAllRequests="true" to the <modules> tag:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
</system.webServer>
(More details/copied from here: http://www.west-wind.com/weblog/posts/2011/Mar/27/ASPNET-Routing-not-working-on-IIS-70)
Chris' answer got me to check whether the app pool was actually configured for .net 4. Sure enough, this server defaults to creating 32-bit .net 2 pools in classic mode.
Ensure that your app is using 4.0 and you'll probably want Integrated pipeline for all new development. 32/64 is mainly up to your dependencies. The default is leaving "allow 32 bit allocations" set to false.
In my case, a similar error was thrown because StaticFile Handler was disabled / not working properly. I eventually fixed it by removing the handler and re-adding it through the web.config. Also, in case of a 403.3 error, change the RequireAccess-property value from "Write" to "Read"
<configuration>
<system.webServer>
<handlers>
<remove name="StaticFile"
<add
name="StaticFile"
path="*" verb="*"
modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule"
resourceType="Either"
requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
So I found the error. There was a left over default document in the root, which isn't necessary for apps using the integrated pipeline. Also some changes to Global.ascx and route registration was neessary, but after that it worked.

Setting up separate ASP.NET app with DotNetNuke

I've got DotNetNuke (v5.1.4 Community Edition) setup on a Windows Server 2008 64-bit system (using SQL Server 2008 64-bit for the backend database), and I want to reference a separate ASP.NET application from it. I plan to display the ASP.NET application via an IFrame module on the DNN site. I'd like the ASP.NET application to recognize the user that is currently logged into the DNN site. I'm trying to do this by creating a web application (in IIS) under the DNN web site on the web server. That is, the ASP.NET web application is a child of the DNN web site (we're using IIS7).
When I do this and then navigate to the ASP.NET site I get this error message:
"Could not load file or assembly
'DotNetNuke.HttpModules' or one of its
dependencies."
Based on this article. I added the < clear / > tag to the httpModules section of the ASP.NET applications web.config.
Now I'm getting this error message:
"Could not load file or assembly
'DotNetNuke' or one of its
dependencies"
Also, the debugging information mentions something about DotNetNuke.UI.WebControls.CaptchaHandler, but I don't think that's the source of the problem. That is, it's just a coincidence that the CaptchaHandler is the first item in the httpHandlers section.
I tried adding the < clear / > tag to the httpHandlers section, but get this error message:
"No http handler was found for request
type 'GET'"
Any ideas on what might be going on and how to fix it?
You can modify the root dnn web.config and add <location inheritInChildApplications="false"> around the <system.webServer> and <system.web> tags.
The end result will be something along these lines...
<location path="." inheritInChildApplications="false">
<system.webServer>
...
</system.webServer>
<system.web>
...
</system.web>
</location>
Well I think you may have missed a step from that post - what you need to do is in the application that is sitting 'below' dnn make sure that you remove the http modules in its web.config. It doesnt sound like you have done that.