webserviceauthenticationevent.cs

来自「Other things about csharp. you could lea」· CS 代码 · 共 68 行

CS
68
字号
namespace Microsoft.WebServices.Security {
    using System;
    using System.Web;
    using System.Security.Principal;

    public class WebServiceAuthenticationEvent : EventArgs {
		private IPrincipal						_IPrincipalUser;
		private HttpContext						_Context;
		private string							_User;
		private string							_Password;

		public WebServiceAuthenticationEvent(HttpContext context){
		    _Context = context;
		}

		public WebServiceAuthenticationEvent(HttpContext context, string user, string password){
		    _Context = context;
			_User = user;
			_Password = password;
		}


		public  HttpContext Context 
		{ 
			get { return _Context;}
		}

		public IPrincipal Principal 
		{ 
			get { return _IPrincipalUser;} 
			set { _IPrincipalUser = value;}
		}

		public void Authenticate()
		{
			GenericIdentity i = new GenericIdentity(User);
			this.Principal = new GenericPrincipal(i, new String[0]);
		}

		public void Authenticate(string[] roles)
		{
			GenericIdentity i = new GenericIdentity(User);
			this.Principal = new GenericPrincipal(i, roles);
		}

		public string User 
		{
			get { return _User; }
			set { _User = value; }
		}

		public string Password
		{
			get { return _Password; }
			set { _Password = value; }
		}

		public bool HasCredentials {
			get {
				if ((_User == null) || (_Password == null))
					return false;

				return true;
			}
		}
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?