我的 .NET 4.0 Web 应用程序项目中有一个 WCF 端点。使用VS2010 WCF测试客户端,我可以正确连接到该服务。但是,当我使用该服务时,我收到一条通用错误消息:
The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were:
我发现当我从 web.config 文件中删除身份验证时,服务可以正常工作:
<authentication mode="Forms">
<forms cookieless="AutoDetect" loginUrl="~/Security/LoginClient.aspx" name="FORMAUTH" />
</authentication>
有什么想法可以如何从身份验证中删除此服务吗?
最佳答案
您可以使用 web.config 中的位置节点从表单例份验证中排除特定文件:
<location path="MyService.svc">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
一种更简单的方法是将不需要身份验证的服务相关文件分组到公共(public)文件夹中并允许访问整个文件夹:
<location path="MyServiceFolder/">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
MSDN 上有关位置元素的更多信息:
http://msdn.microsoft.com/en-us/library/b6x6shw7%28vs.71%29.aspx
关于asp.net - 身份验证模式 ="Forms"导致 WCF 端点出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593720/