📄 global.asax.cs
字号:
/*** 北京林业大学 计00-3班 吴鹏组编写* 组员:高显俊,郗嘉,吴鹏,王海,苏荣* 最后生成时间: 2003.5.31* 本网站借鉴了dotnetjunkies网站的背景和CSS,特此声明* 并提供一切源代码,遵守GPL版权声明* GPL版权声明在doc/license.txt中,人员分工在doc/summary.txt中* 开发标准在doc/programming standard.doc中,需求声明在doc/requirements.doc中* 开发计划在doc/plans.doc中,面向对象软件设计说明书在doc/brochure.doc 中*/using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Security;
using System.Security.Principal;
using System.Web.Security;
using Park.Common;
namespace Park
{
/// <summary>
/// Global 的摘要说明。
/// </summary>
public class Global : System.Web.HttpApplication
{
public Global()
{
InitializeComponent();
}
#region Web Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Global
//
this.AuthenticateRequest += new System.EventHandler(this.Park_AuthenticateRequest);
}
#endregion
/// <summary>
/// Add Database Access to Verify User
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Park_AuthenticateRequest(object sender, System.EventArgs e)
{
//Execute First
//TODO:Add Database Access to Verify User
HttpCookie cookie=Request.Cookies[CookieKey.Ticket];
// Create the roles cookie if it doesn't exist yet for this session.
if ( cookie== null || cookie.Value == "")
{
// Create a cookie authentication ticket.
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // version
ConfigurationKey.DefaultUser, // user name
DateTime.Now, // issue time
DateTime.Now.AddHours(1), // expires every hour
false, // don't persist cookie
"" // roles
);
// Encrypt the ticket
String cookieStr = FormsAuthentication.Encrypt(ticket);
// Send the cookie to the client
Response.Cookies[CookieKey.Ticket].Value = cookieStr;
Response.Cookies[CookieKey.Ticket].Path = "/";
Response.Cookies[CookieKey.Ticket].Expires = DateTime.Now.AddMinutes(1);
// Add our own custom principal to the request containing the roles in the auth ticket
Context.User = new GenericPrincipal(new GenericIdentity(ConfigurationKey.DefaultUser), new string[]{""});
}
else
{
// Get roles from roles cookie
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Context.Request.Cookies[CookieKey.Ticket].Value);
// Add our own custom principal to the request containing the roles in the auth ticket
Context.User = new GenericPrincipal(new GenericIdentity(ticket.Name), new string[]{""});
}
}
/*
/// <summary>
/// Global application level error handling. This method is invoked
/// anytime an exception is thrown.
/// </summary>
/// <param name="sender">Sender</param>
/// <param name="e">Event arguments</param>
private void Application_Error(object sender, System.EventArgs e)
{
string err = "Park Application Error\n\n";
err += "Request: " + Request.Url.ToString() + "\n\n";
err += "Strack Trace: \n" + Server.GetLastError().ToString();
// write the error message to the NT Event Log
Common.Error.Log(err);
}
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -