【发布时间】:2011-06-10 14:05:43
【问题描述】:
我有一个 WCF HTTP REST 服务,我将它与一个使用不同编程语言的 HTTP 客户端绑定在一起,该客户端编写自己的自定义 HTTP。 我想为我的 WCF 服务添加 WWW-Authenticate 基本身份验证支持。
我的方法如下所示:
[WebInvoke(UriTemplate = "widgets", Method = "POST")]
public XElement CreateWidget(XElement e)
{
...
}
我是否有可能以某种方式过滤传入的 HTTP 请求,以便在它遇到每个 REST 方法(如上面的 CreateWidget)之前检查有效的基本身份验证字符串?
注意:我的身份验证信息存储在我的数据库中。
基本上我想在请求标头中检查这一点:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 然后我可以自己解析该字符串并验证数据库中的 u/p。
web.config文件如下:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="10485760" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="1048576" maxBufferSize="1048576" />
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
【问题讨论】:
标签: wcf http authentication