Tag: 摘要

如何使用HttpWebRequest进行摘要式身份validation?

我发现的各种文章( 1,2 )使这看起来很容易: WebRequest request = HttpWebRequest.Create(url); var credentialCache = new CredentialCache(); credentialCache.Add( new Uri(url), // request url “Digest”, // authentication type new NetworkCredential(“user”, “password”) // credentials ); request.Credentials = credentialCache; 但是,这仅适用于没有URL参数的URL。 例如,我可以下载http://example.com/test/xyz.html ,但是当我尝试下载http://example.com/test?page=xyz ,结果是400 Bad Request消息在服务器的日志中运行以下内容(运行Apache 2.2): Digest: uri mismatch – does not match request-uri 我的第一个想法是摘要规范要求从摘要哈希中删除URL参数 – 但是从传递给credentialCache.Add()的URL中删除参数并没有改变。 所以它必须是相反的方式,在.NET框架中的某个地方错误地从URL中删除参数。

如何强制inheritance类在C#中实现静态方法?

我想要做的就是确保类Item的子类实现静态方法,并且我希望在编译时检查它以避免运行时错误。 使用静态方法的抽象类似乎不起作用: 错误:无法将静态成员标记为覆盖,虚拟或抽象 public abstract class Item { public static abstract Item GetHistoricalItem(int id, DateTime pastDateTime); } public class Customer : Item { public static override Customer GetHistoricalItem(int id, DateTime pastDateTime) { return new Customer(); } } public class Address : Item { public static override Address GetHistoricalItem(int id, DateTime pastDateTime) { return new Address(); […]