📄 webadminpage.cs
字号:
return NewUser;
}
public override string GetUserNameByEmail(string email)
{
return (string)CallWebAdminMembershipProviderHelperMethod("GetUserNameByEmail", new object[]{email}, new Type[] {typeof(string)});
}
public override string ResetPassword(string name, string answer)
{
return (string)CallWebAdminMembershipProviderHelperMethod("ResetPassword", new object[]{name, answer}, new Type[] {typeof(string), typeof(string)});
}
public override void UpdateUser(MembershipUser user)
{
string typeFullName = "System.Web.Security.MembershipUser, " + typeof(HttpContext).Assembly.GetName().ToString();;
Type tempType = Type.GetType(typeFullName);
CallWebAdminMembershipProviderHelperMethod("UpdateUser", new object[] {(MembershipUser) user}, new Type[] {tempType});
}
public override bool ValidateUser(string name, string password)
{
return (bool)CallWebAdminMembershipProviderHelperMethod("ValidateUser", new object[]{name, password}, new Type[] {typeof(string), typeof(string)});
}
public override MembershipUser GetUser( object providerUserKey, bool userIsOnline )
{
return (MembershipUser)CallWebAdminMembershipProviderHelperMethod("GetUser", new object[]{providerUserKey, userIsOnline}, new Type[] {typeof(object), typeof(bool)});
}
public override bool UnlockUser( string name )
{
return (bool)CallWebAdminMembershipProviderHelperMethod("UnlockUser", new object[]{name}, new Type[] {typeof(string)});
}
public override void Initialize(string name, NameValueCollection config)
{
if (String.IsNullOrEmpty(name)) {
name = "WebAdminMembershipProvider";
}
base.Initialize(name, config);
}
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
{
totalRecords = 0;
MembershipUserCollection TempList = (MembershipUserCollection)CallWebAdminMembershipProviderHelperMethod("FindUsersByName", new object[]{usernameToMatch, pageIndex, pageSize, totalRecords}, new Type[] {typeof(string), typeof(int), typeof(int), Type.GetType("System.Int32&")});
MembershipUserCollection NewList = new MembershipUserCollection();
foreach (MembershipUser TempItem in TempList)
{
MembershipUser NewUser = new MembershipUser(this.Name,
TempItem.UserName,
TempItem.ProviderUserKey,
TempItem.Email,
TempItem.PasswordQuestion,
TempItem.Comment,
TempItem.IsApproved,
TempItem.IsLockedOut,
TempItem.CreationDate,
TempItem.LastLoginDate,
TempItem.LastActivityDate,
TempItem.LastPasswordChangedDate,
TempItem.LastLockoutDate );
NewList.Add(NewUser);
}
return NewList;
}
}
public sealed class WebAdminRemotingManager : MarshalByRefObject {
private ApplicationManager _appManager;
private string _applicationMetaPath;
private string _applicationPhysicalPath;
private HttpSessionState _session;
private object _configurationHelper;
private static string _assemblyVersion;
public WebAdminRemotingManager(string applicationMetaPath, string applicationPhysicalPath, HttpSessionState session) {
_applicationMetaPath = applicationMetaPath;
_applicationPhysicalPath = applicationPhysicalPath;
_session = session;
}
public override Object InitializeLifetimeService(){
return null; // never expire lease
}
public static string AssemblyVersionString {
get {
if (String.IsNullOrEmpty(_assemblyVersion)) {
_assemblyVersion = "System.Web.Administration.WebAdminConfigurationHelper, " + typeof(HttpContext).Assembly.GetName().ToString();
}
return _assemblyVersion;
}
}
private ApplicationManager AppManager {
get {
if (_appManager == null) {
return _appManager = ApplicationManager.GetApplicationManager();
}
return _appManager;
}
}
protected string ApplicationMetaPath {
get {
return _applicationMetaPath;
}
}
public string ApplicationPhysicalPath {
get {
return _applicationPhysicalPath;
}
set {
_applicationPhysicalPath = value;
// Set provider proxy references to null, to account for the edge case where ApplicationPhysicalPath is set twice.
// Notes: this does not shut down the target appdomain, which is the desired behavior, since, in the unlikely case where the
// ApplicationPhysicalPath is changed, the change is likely to be reverted. Resetting the providers is necessary because
// the existing providers point to the old target appdomain.
ResetProviders();
}
}
public object ConfigurationHelperInstance {
get {
return CreateConfigurationHelper();
}
}
private HttpSessionState Session {
get {
return _session;
}
}
public string TargetAppId {
get {
if (Session["WebAdminTargetAppId"] != null) {
return (string)Session["WebAdminTargetAppId"];
} else {
return string.Empty;
}
}
set {
Session["WebAdminTargetAppId"] = value;
}
}
private object CreateConfigurationHelper() {
if (_configurationHelper != null) {
return _configurationHelper;
}
string appPath = ApplicationMetaPath;
string appPhysPath = ApplicationPhysicalPath;
string targetAppId = String.Empty;
string typeFullName = WebAdminRemotingManager.AssemblyVersionString;
Type tempType = Type.GetType(typeFullName);
// Put together some unique app id
string appId = (String.Concat(appPath, appPhysPath).GetHashCode()).ToString("x", CultureInfo.InvariantCulture);
_configurationHelper = (object)ApplicationManager.GetApplicationManager().CreateObject(appId, tempType, appPath, appPhysPath, false, true);
TargetAppId = appId;
return _configurationHelper;
}
private void EnsureTargetAppId() {
if (TargetAppId != null) {
return;
}
// In some cases, the target appdomain exists before the AppId is discovered by AppManager.CreateObjectWithDefaultAppHostAndAppId
// (for example if the target app is already running). In this case, retrieve one of the
// providers (we make an arbitrary choice to retrieve the membership provider). This forces the object to
// discover the target appid.
CreateConfigurationHelper(); // Retrieves the target appid.
}
public VirtualDirectory GetVirtualDirectory(string virtualDir) {
VirtualDirectory vdir = null;
object configHelperObject = ConfigurationHelperInstance;
if (configHelperObject != null) {
string typeFullName = WebAdminRemotingManager.AssemblyVersionString;
Type tempType = Type.GetType(typeFullName);
BindingFlags allBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo method = tempType.GetMethod("GetVirtualDirectory", allBindingFlags);
if (method != null) {
vdir = (VirtualDirectory) method.Invoke(configHelperObject, new object[]{virtualDir});
}
}
return vdir;
}
public void ResetProviders() {
_configurationHelper = null;
TargetAppId = null;
}
public void ShutdownTargetApplication() {
// CONSIDER: Rather than calling EnsureTargetAppId(), is there a method on AppManager that can tell us whether
// an appdomain exists based on the Id, and another method that creates the "default Id" from the application
// path and physical path? This prevents the following two lines from creating the appdomain and immediately
// shutting it down in the (edge) case where the target appdomain doesn't exist.
EnsureTargetAppId();
AppManager.ShutdownApplication(TargetAppId);
// ResetProviders to ensure that the value of TargetAppId is in sync with the provider proxies. Calling
// property get for a provider proxy sets TargetAppId to the correct value.
ResetProviders();
}
}
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class WebAdminUserControl : UserControl {
private string _directionality;
public enum DatabaseType {
Access = 0,
Sql = 1,
}
public string Directionality {
get {
if (String.IsNullOrEmpty(_directionality)) {
_directionality = ((string) GetGlobalResourceObject("GlobalResources", "HtmlDirectionality")).ToLower();
}
return _directionality;
}
}
public HorizontalAlign DirectionalityHorizontalAlign {
get {
if (Directionality == "rtl") {
return HorizontalAlign.Right;
} else {
return HorizontalAlign.Left;
}
}
}
public virtual bool OnNext() {
return true; // move to next control. Override to return false if next should not be honored.
}
public virtual bool OnPrevious() {
return true; // move to next control. Override to return false if prev should not be honored.
}
}
[Serializable]
public class WebAdminException : Exception
{
public WebAdminException() {}
public WebAdminException( string message )
: base( message )
{}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -