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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
//
// System.Web.Hosting.AppDomainFactory.cs
//
// Authors:
// Bob Smith <bob@thestuff.net>
// Gonzalo Paniagua (gonzalo@ximian.com)
//
// (C) Bob Smith
// (c) Copyright 2002 Ximian, Inc. (http://www.ximian.com)
//
using System;
using System.Collections;
using System.IO;
using System.Security;
using System.Security.Policy;
using System.Text;
namespace System.Web.Hosting
{
public sealed class AppDomainFactory : IAppDomainFactory
{
static int nDomain = 0;
static string [] domainData = { ".appDomain",
".appId",
".appPath",
".appVPath",
".appName",
".domainId"
};
public object Create (string module,
string typeName,
string appId,
string appPath,
string strUrlOfAppOrigin,
int iZone)
{
appPath = Path.GetFullPath (appPath);
if (appPath [appPath.Length - 1] == '\\')
appPath += '\\';
StringBuilder sb = new StringBuilder (appId);
sb.Append ('-');
lock (domainData){
sb.Append (nDomain.ToString ());
nDomain++;
}
sb.Append ('-' + DateTime.Now.ToString ());
string domainId = sb.ToString ();
sb = null;
int slash = appId.IndexOf ('/');
string vPath;
if (slash == -1)
vPath = "/";
else
vPath = appId.Substring (slash + 1);
string appName = (appId.GetHashCode () + appPath.GetHashCode ()).ToString ("x");
AppDomainSetup domainSetup = new AppDomainSetup ();
PopulateDomainBindings (domainId,
appId,
appName,
appPath,
vPath,
domainSetup,
null);
// May be adding more assemblies and such to Evidence?
AppDomain domain = AppDomain.CreateDomain (domainId,
AppDomain.CurrentDomain.Evidence,
domainSetup);
string [] settings = new string [6];
settings [0] = "*";
settings [1] = appId;
settings [2] = appPath;
settings [3] = vPath;
settings [4] = appName;
settings [5] = domainId;
for (int i = 0; i < 6; i++)
domain.SetData (domainData [i], settings [i]);
object o = null;
try {
o = domain.CreateInstance (module, typeName);
} catch {
AppDomain.Unload (domain);
o = null;
}
return o;
}
internal static void PopulateDomainBindings (string domainId,
string appId,
string appName,
string appPath,
string appVPath,
AppDomainSetup setup,
IDictionary dict)
{
setup.PrivateBinPath = "bin";
setup.PrivateBinPathProbe = "*";
setup.ShadowCopyFiles = "true";
//HACK: we should use Uri (appBase).ToString () once Uri works fine.
string uri = "file://" + appPath;
if (Path.DirectorySeparatorChar != '/')
uri = uri.Replace (Path.DirectorySeparatorChar, '/');
setup.ApplicationBase = uri;
setup.ApplicationName = appName;
string temp = Path.GetTempPath ();
setup.DynamicBase = Path.Combine (temp, Environment.UserName + "-temp-aspnet");
string webConfigName = Path.Combine (appPath, "Web.config");
if (File.Exists (webConfigName))
setup.ConfigurationFile = webConfigName;
else
setup.ConfigurationFile = Path.Combine (appPath, "web.config");
if (dict != null) {
dict.Add (domainData [0], "*");
dict.Add (domainData [1], appId);
dict.Add (domainData [2], appPath);
dict.Add (domainData [3], appVPath);
dict.Add (domainData [4], appName);
dict.Add (domainData [5], domainId);
}
}
}
}
|