⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.asax.cs

📁 模拟数据库
💻 CS
字号:
//=====================================================================
//
// THIS CODE AND INFORMATION IS PROVIDED TO YOU FOR YOUR REFERENTIAL
// PURPOSES ONLY, AND IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE,
// AND MAY NOT BE REDISTRIBUTED IN ANY MANNER.
//
// Copyright (C) 2003  Microsoft Corporation.  All rights reserved.
//
//=====================================================================
using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Security.Principal;

namespace SqlWebAdmin
{
    public class Global : System.Web.HttpApplication
    {
        /// <summary>
        /// Required designer variable for global functions and variables.
        /// </summary>

        private System.ComponentModel.IContainer components = null;

        protected void Application_Error(Object sender, EventArgs e)
        {
            Application.Add("Error", Server.GetLastError());
            // If an error occurs anywhere in the application, it will be saved
            // as an application variable, which can be easily displayed
            // by redirecting the user to the Error.aspx page.
        }

        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
        {

            if (Context.User == null)
            {

                String cookieName = FormsAuthentication.FormsCookieName;
                HttpCookie authCookie = Context.Request.Cookies[cookieName];

                if (null == authCookie)
                {
                    //There is no authentication cookie.
                    return;
                }
                FormsAuthenticationTicket authTicket = null;
                try
                {
                    authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                }
                catch (Exception ex)
                {
                    //Write the exception to the Event Log.
                    return;
                }
                if (null == authTicket)
                {
                    //Cookie failed to decrypt.
                    return;
                }

                string[] loginType = authTicket.UserData.Split(new char[] { ',' }); ;
                GenericIdentity id = new GenericIdentity(authTicket.Name, "webAuth");
                //This principal flows throughout the request.
                GenericPrincipal principal = new GenericPrincipal(id, loginType);
                Context.User = principal;


            }
            //Context.User = (System.Security.Principal.IPrincipal)System.Security.Principal.WindowsIdentity.GetCurrent();

        }


        public Global()
        {
            InitializeComponent();
        }

        #region Web Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
        }
        #endregion
    }
}

⌨️ 快捷键说明

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