0

ハンドラー クラスを作成し、認証を検証する方法を知りたいと思いました。また、いくつかのネットワーク資格情報を含めたテスト用の XML 投稿も作成しました。これらのネットワーク資格情報をハンドラーで読み取り/検証するには何が必要ですか?

ハンドラ:

public class HelloWorldHandler : IHttpHandler {
public HelloWorldHandler() {}

    public void ProcessRequest(HttpContext context){

    HttpRequest request = context.Request;
    HttpResponse response = context.Response;

    var stream = context.Request.InputStream; 
    byte[] buffer = new byte[stream.Length]; 
    stream.Read(buffer, 0, buffer.Length); 
    string xml = Encoding.UTF8.GetString(buffer);
}

public bool IsReusable
{
    // To enable pooling, return true here.
    // This keeps the handler in memory.
    get { return false; }
}

XML 投稿スニペット:

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

        byte[] requestBytes = System.Text.Encoding.UTF8.GetBytes(xml);
        req.Method = "POST";
        req.ContentType = "text/xml;charset=utf-8";
        req.ContentLength = requestBytes.Length;
        req.Credentials = new NetworkCredential("Test", "Password");
        Stream requestStream = req.GetRequestStream();
        requestStream.Write(requestBytes, 0, requestBytes.Length);
4

1 に答える 1

2

私は、HttpContextがそのすべての情報を提供することになっていると思います。何かのようなもの:

context.User.Identity.IsAuthenticated

すべてが構成されている場合は、これを適切に設定する必要があります。

于 2012-06-13T19:45:38.033 に答える