blob: 0bbca5ecb8addda9858de91376266b742222d047 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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;
/// <summary>
/// Hosts a 'portable' version of the OpenIdProvider for testing itself and the
/// RelyingParty against it.
/// </summary>
class AspNetHost : MarshalByRefObject {
HttpHost httpHost;
public AspNetHost() {
httpHost = HttpHost.CreateHost(this);
////if (!UntrustedWebRequestHandler.WhitelistHosts.Contains("localhost"))
//// UntrustedWebRequestHandler.WhitelistHosts.Add("localhost");
}
public Uri BaseUri {
get { return httpHost.BaseUri; }
}
public static AspNetHost CreateHost(string webDirectory) {
AspNetHost host = (AspNetHost)ApplicationHost.
CreateApplicationHost(typeof(AspNetHost), "/", webDirectory);
return host;
}
public string ProcessRequest(string url) {
return httpHost.ProcessRequest(url);
}
public string ProcessRequest(string url, string body) {
return 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() {
httpHost.Dispose();
}
}
}
|