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

📄 global.asax.cs

📁 ASP.net网站开发四“酷”全书:新闻、论坛、电子商城、博客_源码
💻 CS
字号:
using System;
using System.Web;
using System.Diagnostics;
using System.Configuration;

namespace BookShop.Web
{
	public class Global : HttpApplication
	{
		// Read in the name of the event log to use from web.config
		private static string LOG_SOURCE = ConfigurationSettings.AppSettings["Event Log Source"];

		protected void Application_Error(object sender, EventArgs e)
		{
			// If an exception is thrown in the application then log it to an event log
			Exception x = Server.GetLastError().GetBaseException();
			EventLog.WriteEntry(LOG_SOURCE, x.ToString(), EventLogEntryType.Error);
		}

		/// <summary>
		/// Custom caching using the VaryByCustom attribute in the 
		/// OuputCache directive.
		/// </summary>
		/// <param name="context">The current HTTP request</param>
		/// <param name="arg">Custom cache argument</param>
		/// <returns>Cache key</returns>
		public override string GetVaryByCustomString(HttpContext context, String arg) {

			// cache key that is returned
			string cacheKey = "";
			
			switch(arg) {

				// Custom caching for header control. We want to create two views
				// of the header... one if the user is logged in and another if
				// they are logged out.
				// We us the forms authentication flag to check if the user is logged in or not

				// Category page
				case "CategoryPageKey":

					if (Request.IsAuthenticated == true) {
						cacheKey = "QQQ" + WebComponents.CleanString.InputText(context.Request.QueryString["categoryId"], 50) + WebComponents.CleanString.InputText(context.Request.QueryString["page"], 15);
					}
					else {
						cacheKey = "AAA" + WebComponents.CleanString.InputText(context.Request.QueryString["categoryId"], 50) + WebComponents.CleanString.InputText(context.Request.QueryString["page"], 15);
					}

					break;

				// Search page
				case "SearchPageKey" : 

					if (Request.IsAuthenticated == true) {
						cacheKey = "QQQ" + WebComponents.CleanString.InputText(context.Request.QueryString["keywords"], 50) + WebComponents.CleanString.InputText(context.Request["page"], 15);
					}
					else {
						cacheKey = "AAA" + WebComponents.CleanString.InputText(context.Request.QueryString["keywords"], 50) + WebComponents.CleanString.InputText(context.Request["page"], 15);
					}

					break;

				// Item page
				case "ItemPageKey" :

					if (Request.IsAuthenticated == true) {
						cacheKey = "QQQ" + WebComponents.CleanString.InputText(context.Request.QueryString["productId"], 50) + WebComponents.CleanString.InputText(context.Request.QueryString["page"], 15);
					}
					else {
						cacheKey = "AAA" + WebComponents.CleanString.InputText(context.Request.QueryString["productId"], 50) + WebComponents.CleanString.InputText(context.Request.QueryString["page"], 15);
					}

					break;

				// Item details page
				case "ItemDetailsPageKey" :

					if (Request.IsAuthenticated == true) {
						cacheKey = "QQQ" + WebComponents.CleanString.InputText(context.Request.QueryString["itemId"], 50);
					}
					else {
						cacheKey = "AAA" + WebComponents.CleanString.InputText(context.Request.QueryString["itemId"], 50);
					}

					break;


				// Used for pages such as help and default
				case "UserId" : 

					if (Request.IsAuthenticated == true) {
						cacheKey = "UserIdIn";
					}
					else {
						cacheKey = "UserIdOut";
					}

					break;
			}

			return cacheKey;
		}
	}
}

⌨️ 快捷键说明

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