//-----------------------------------------------------------------------
//
// Copyright (c) Andrew Arnott. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.Hosting {
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Web;
using System.Web.Hosting;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Test.OpenId;
///
/// Hosts a 'portable' version of the OpenIdProvider for testing itself and the
/// RelyingParty against it.
///
internal class AspNetHost : MarshalByRefObject {
private HttpHost httpHost;
public AspNetHost() {
this.httpHost = HttpHost.CreateHost(this);
////if (!UntrustedWebRequestHandler.WhitelistHosts.Contains("localhost"))
//// UntrustedWebRequestHandler.WhitelistHosts.Add("localhost");
}
public Uri BaseUri {
get { return this.httpHost.BaseUri; }
}
public static AspNetHost CreateHost(string webDirectory) {
AspNetHost host = (AspNetHost)ApplicationHost.
CreateApplicationHost(typeof(AspNetHost), "/", webDirectory);
return host;
}
public string ProcessRequest(string url) {
return this.httpHost.ProcessRequest(url);
}
public string ProcessRequest(string url, string body) {
return this.httpHost.ProcessRequest(url, body);
}
public void BeginProcessRequest(HttpListenerContext context) {
ThreadPool.QueueUserWorkItem(state => { ProcessRequest(context); });
}
public void ProcessRequest(HttpListenerContext context) {
try {
using (TextWriter tw = new StreamWriter(context.Response.OutputStream)) {
HttpRuntime.ProcessRequest(new TestingWorkerRequest(context, tw));
}
} catch (Exception ex) {
Logger.Error("Exception in AspNetHost", ex);
throw;
}
}
public void CloseHttp() {
this.httpHost.Dispose();
}
}
}