mystathandler.cs

来自「《精通ASP.NET2.0网络应用系统开发》书中的源码」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.Web;

namespace webvisitStatistic.HitsHandler
{
	/// <summary>
	/// MyStatHandler 的摘要说明。
	/// </summary>
	public class MyStatHandler : IHttpHandler
	{
		public MyStatHandler()
		{
			//
			// TODO: 在此处添加构造函数逻辑
			//
		}
		#region IHttpHandler 成员

		public void ProcessRequest(HttpContext context)
		{
			// TODO:  添加 MyStatHandler.ProcessRequest 实现
			HttpRequest request = context.Request;
			HttpResponse response = context.Response;
			String webid = request.QueryString["webid"];
			if (String.Empty==webid) webid = "10001";
			String str = String.Format( resScript1 ,GetBaseUrl() ,request.QueryString["style"],request.QueryString["webid"] );
			response.Write(str+"\n"+resScript2);
			response.End();
		}

		public bool IsReusable
		{
			get
			{
				// TODO:  添加 MyStatHandler.IsReusable getter 实现
				return true;
			}
		}

		#endregion


		/// <summary>
		/// ? 如何得到当前网站的基地址
		/// </summary>
		/// <returns></returns>
		protected String GetBaseUrl()
		{
			return "http://localhost/webvisitStatistic";
		}
		private const String resScript3 = @"document.write(""<a href={0}/Default.aspx target=_blank><img src={1}/illegal.gif border=0 alt={2}></a>"")";
		protected const String resScript1 = @"document.write(""<script>var url='{0}';var style='{1}';var webid='{2}'</script>"");";
		protected const String resScript2 = 
			@"document.write(""<script src=""+url+""/hitsReport.ch?style=""+style+""&webid=""+webid+""&referer=""+escape(document.referrer)+""&screenwidth=""+screen.width+""></script>"");";

	}
}

⌨️ 快捷键说明

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