📄 global.asax
字号:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
//移转匿名用户Profile设置文件
void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args)
{
//取得匿名用户Profile
ProfileCommon anonymousProfile = Profile.GetProfile(args.AnonymousID);
//将匿名用户Profile的阅读偏好设置到登录者Profile的阅读偏好
if (!string.IsNullOrEmpty(anonymousProfile.阅读偏好))
{
Profile.阅读偏好 = anonymousProfile.阅读偏好;
Profile.Save();
}
//删除匿名用户Profile
ProfileManager.DeleteProfile(args.AnonymousID);
//清除匿名用户Cookie或身份资料
AnonymousIdentificationModule.ClearAnonymousIdentifier();
}
//Profile个性化事件
public void Profile_Personalize(object sender, ProfileEventArgs args)
{
ProfileCommon userProfile;
//检查User是否为null
if (User == null)
{
return;
}
//取得用户Profile
userProfile = (ProfileCommon)ProfileBase.Create(User.Identity.Name);
//判断User属于哪个角色群组,就将该角色群组的Profile指定给User
//如此做的原因是网站不一定会针对每个User做Profile,而是针对角色
//来设置权限,接着再将角色的Profile指派给User
string[] RolesArray = Roles.GetRolesForUser(User.Identity.Name);
if (RolesArray.Length > 0)
{
string txtRole = RolesArray[0];
switch (txtRole)
{
case "Administrator":
userProfile = userProfile.GetProfile("AdminProfile");
break;
case "MIS":
userProfile = userProfile.GetProfile("MisProfile");
break;
case "RD":
userProfile = userProfile.GetProfile("RdProfile");
break;
case "Sales":
userProfile = userProfile.GetProfile("SalesProfile");
break;
default:
userProfile = null;
break;
}
if (userProfile != null)
{
args.Profile = userProfile;
}
else
{
args.Profile = null;
}
}
}
//Profile自动存储事件
void Profile_ProfileAutoSaving(object sender, ProfileAutoSaveEventArgs args)
{
if (args.Context.Items["ProfileAutoSaveState"]!=null &&((bool)args.Context.Items["ProfileAutoSaveState"]) == false)
{
//关闭Profile自动存储
args.ContinueWithProfileAutoSave = false;
}
else
{
//开启Profile自动存储
args.ContinueWithProfileAutoSave = true;
}
}
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -