Compatibility error on WCF rest service - asp.net

when I added
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
in wcf rest service and
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
in webconfig
im getting error as
The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.
Actually its working fine when I run service in localhost but its throwing the error when I host the service..
Actually I need this bcos im planning to implement caching in wcf rest service..
Please help ....

you can do this by updating you web.config file as follows:
<system.webServer>
<security>
<authentication>
<basicAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>

Related

Disable Basic-Authentication without IIS manager

My ASP.NET MVC web application handles the authentication itself by explicitly sending the 401 status code and the www-authenticate header to make the browser display the basic authentication dialog.
My hosting provider doesn't provide access to the IIS manager and has the IIS BasicAuthenticationModule always enabled.
Unfortunately, the custom basic authentication implemented by my application is therefore now "hidden" by the IIS BasicAuthenticationModule. Any time I send a 401, the BasicAuthenticationModule seems to think it's his responsibility to handle the authentication. It also overrides the custom www-authenticate header of my application.
Is there a way to disable the IIS module for just my web application using the web.config only? I already tried adding the following settings to the web.config:
<configuration>
<system.webServer>
<modules>
<remove name="BasicAuthenticationModule" />
</modules>
</system.webServer>
</configuration>
But that just generates a lock violation error. This setting didn't do the trick either:
<configuration>
<system.web>
<authentication mode="None" />
</system.web>
</configuration>
Any other suggestions?
If you disable any authentication on IIS manager and check web.config, you will find that there is no configuration about authentication in it. Because configurations are saving in applicationhost.config file. That is why you need to use IIS manager.(Only administrator can use IIS manager)
But according to microsoft docs, you can use appcmd to configure these settings. This commits the configuration settings to the appropriate location section in the ApplicationHost.config file.
appcmd.exe set config "site name" -section:system.webServer/security/authentication/basicAuthentication /enabled:"False" /commit:apphost

CAS policy Error

please, someone can help me to fix this error, "This method implicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility, please use the NetFx40_LegacySecurityPolicy configuration switch." I can not generate my pdf files. it's an Asp.Net application to host on a Win 2008 R2 server. IIS 6.5. I already added
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
in my web.config but it did not solve the problem.
The error occurs because CAS policy is obsolete in .net Framework 4.0. The Xml node you've added is for Windows Forms applications. For Web applications, please add the following in web.config:
<system.web>
<trust legacyCasModel="true"/>
</system.web>

Add AspNetCompatibilityRequirements attribute to Biztalk Wcf service

I'm trying to get a Biztalk 2009 WCF receive location lockdown per a permissions requirement so only a certain group of users can access the WSDL and service using Authorization Rules in the services web.config
<authorization>
<allow users="uuu\InterfaceUser" />
<allow roles="AllowedTeam" />
<deny users="*" />
</authorization>
I've enabled the following in the web.config figuring it would do the trick.
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
and came across the error
The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as 'Allowed' or 'Required'.
I know what I would need to do is add the following:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
to the service, but the generated through the Biztalk WCF service wizard, so I am unsure of how to get this configured.
The receive location is a WCF-CustomIsolated , but I am not seeing a behavior in the transport properties to turn on the AspNetCompatibilityRequirements attribute. BindingType is basicHttp Security is TransportWithMessageCredentials
Any thoughts or guidance would be helpful.
I have to have the authentication on both the service and the wsdl.
After additional research it doesn't look like it will be possible to integrate asp.net compatibility to the service. Which means adding
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
won't be possible.
The solution I did was to infact build a custom behavior to use the ASP.NET URL Authorization Module.
Thanks to Dean May for the solution found at
https://phidiax.com/blog/post/securing-biztalk-wcf-receive-locations

MVC Web Api won't allow Windows Authentication

I have a simple MVC web api 2 IIS hosted application which I want to enable windows authentication (initially not using Owin). I am running this on my development machine and running as local IIS.
So, from what I could find, I need to add the following to the web.config
1: to the following section the authentication mode="Windows"
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5.1"/>
<authentication mode="Windows" />
</system.web>
2: Then add the following
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true"/>
</authentication>
</security>
When I add the above and run the application (in debug from Dev studio), I get the following error
HTTP Error 500.19 - Internal Server Error
Config Error This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
and then it specifically points to this web config entry
Config Source:
37: <authentication>
38: <windowsAuthentication enabled="true"/>
39: </authentication>
Anyone have any ideas why I would be getting this?
Also, I noticed when I switch to IIS express, that in the project properties, the Windows Authentication is set to disabled, and grayed out so I cannot set it here either.
Thanks in advance for any help!
If you read applicationHost.config, you will see that authentication related sections are locked down and cannot be overridden in web.config,
<section name="windowsAuthentication" overrideModeDefault="Deny" />
Thus, you need to specify that in applicationHost.config, instead of web.config. Both IIS and IIS Express have such restriction.

WCF web service gives error after hosting

I have hosted a WCF web service in IIS. But when i fire url I get the following error message.
"IIS specified authentication schemes 'Basic, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used."
You can resolve this issue by disabling the basic authentication on your IIS. It depends that which IIS version you are working with? but for IIS 7, you can do this by updating you web.config file as follows:
<system.webServer>
<security>
<authentication>
<basicAuthentication enabled="false" />
</authentication>
</security>
</system.webServer>

Resources