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
|
//------------------------------------------------------------------------------
// <copyright file="WebAdminConfigurationHelper.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
/************************************************************************************************************/
namespace System.Web.Administration {
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Reflection;
using System.Web;
using System.Web.Hosting;
using System.Web.Management;
using System.Web.Security;
using System.Web.Util;
using System.Web.UI;
using System.Security.Permissions;
[Serializable]
internal sealed class WebAdminConfigurationHelper : MarshalByRefObject, IRegisteredObject {
public WebAdminConfigurationHelper() {
HostingEnvironment.RegisterObject(this);
}
public override Object InitializeLifetimeService() {
return null; // never expire lease
}
public VirtualDirectory GetVirtualDirectory(string path) {
if (HttpRuntime.NamedPermissionSet != null) {
HttpRuntime.NamedPermissionSet.PermitOnly();
}
return HostingEnvironment.VirtualPathProvider.GetDirectory(path);
}
public object CallMembershipProviderMethod (string methodName, object[] parameters, Type[] paramTypes) {
Type tempType = typeof(HttpContext).Assembly.GetType("System.Web.Security.Membership");
object returnObject = null;
BindingFlags allBindingFlags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo method = null;
if (paramTypes != null) {
method = tempType.GetMethod(methodName, allBindingFlags, null, paramTypes, null);
} else {
method = tempType.GetMethod(methodName, allBindingFlags);
}
if (method != null) {
if (HttpRuntime.NamedPermissionSet != null) {
HttpRuntime.NamedPermissionSet.PermitOnly();
}
returnObject = method.Invoke(null, parameters);
}
object[] newValues = new object[parameters.Length + 1];
newValues[0] = returnObject;
int j = 1;
for (int i = 0; i < (parameters.Length); i++) {
newValues[j++] = parameters[i];
}
returnObject = (object) newValues;
return returnObject;
}
public object GetMembershipProviderProperty(string propertyName) {
Type tempType = typeof(HttpContext).Assembly.GetType("System.Web.Security.Membership");
object returnObject = null;
BindingFlags allBindingFlags = BindingFlags.GetProperty | BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
if (HttpRuntime.NamedPermissionSet != null) {
HttpRuntime.NamedPermissionSet.PermitOnly();
}
returnObject = tempType.InvokeMember(propertyName, allBindingFlags, null, null, null, System.Globalization.CultureInfo.InvariantCulture);
return returnObject;
}
public object CallRoleProviderMethod (string methodName, object[] parameters, Type[] paramTypes) {
Type tempType = typeof(HttpContext).Assembly.GetType("System.Web.Security.Roles");
object returnObject = null;
BindingFlags allBindingFlags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo method = null;
if (paramTypes != null) {
method = tempType.GetMethod(methodName, allBindingFlags, null, paramTypes, null);
} else {
method = tempType.GetMethod(methodName, allBindingFlags);
}
if (method != null) {
if (HttpRuntime.NamedPermissionSet != null) {
HttpRuntime.NamedPermissionSet.PermitOnly();
}
returnObject = method.Invoke(null, parameters);
}
object[] newValues = new object[parameters.Length + 1];
newValues[0] = returnObject;
int j = 1;
for (int i = 0; i < (parameters.Length); i++) {
newValues[j++] = parameters[i];
}
returnObject = (object) newValues;
return returnObject;
}
void IRegisteredObject.Stop(bool immediate) {
HostingEnvironment.UnregisterObject(this);
}
}
}
|