pagebase.cs

来自「基于角色的用户验证. 这个程序重点写了四个pages以实现这些功能:增加用户」· CS 代码 · 共 34 行

CS
34
字号
using System;

namespace RolesBasedAthentication.Web
{
	public class PageBase: System.Web.UI.Page
	{
		public PageBase()
		{
		}

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			this.Load += new System.EventHandler(this.PageBase_Load);
		}

		private void PageBase_Load(object sender, System.EventArgs e)
		{									
			if (Context.User.Identity.IsAuthenticated) 
			{
				if (!(Context.User is SitePrincipal))
				{
					// ASP.NET's regular forms authentication picked up our cookie, but we
					// haven't replaced the default context user with our own. Let's do that
					// now. We know that the previous context.user.identity.name is the e-mail
					// address (because we forced it to be as such in the login.aspx page)				
					SitePrincipal newUser = new SitePrincipal( Context.User.Identity.Name );
					Context.User = newUser;
				}
			}
		}
	}
}

⌨️ 快捷键说明

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