我有一个WCF HTTP REST服务,我使用不同编程语言的HTTP客户端编写自己的自定义HTTP.我想为我的WCF服务添加WWW-Authenticate基本身份验证支持.
我的方法看起来像这样:
[WebInvoke(UriTemplate = "widgets", Method = "POST")]
public XElement CreateWidget(XElement e)
{
...
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以某种方式过滤传入的HTTP请求,以便我可以检查有效的Basic auth字符串,然后才能访问上面的每个REST方法CreateWidget?注意:我的身份验证信息在我的数据库中是stord.
基本上我想在请求头中检查这个:
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>
Run Code Online (Sandbox Code Playgroud) 我正在将一些代码从本机C++移植到C#,我需要执行以下操作:
ASCII.GetBytes当它遇到一个unicode字符时它无法识别它返回给我带有十进制数字63(问号)的字符但是在我的C++代码中使用WideCharToMultiByte(CP_ACP, ...当它遇到一个字符时它不知道它使用带有十进制数字37的字符(%符号) .
我的问题是如何使ASCII.GetBytes返回#37而不是#63为未知字符?