设为首页 加入收藏

TOP

记录数据库执行情况来分析数据库查询性能问题(二)
2014-11-24 08:19:30 来源: 作者: 【 】 浏览:14
Tags:记录 数据库 执行 情况 分析 查询 性能 问题
tring Name
{
get;
set;
}
///
/// 上下文ID
///

Guid UniqueID
{
get;
set;
}
///
/// 客户端IP
///

string ClientAddress
{
get;
set;
}

///
/// 应用所在物理路径
///

string ApplicationDirectory
{
get;
set;
}

///
/// 客户端请求的地址
///

string RequestURL
{
get;
set;
}

///
/// 客户端请求的上一URL
///

string ReferURL
{
get;
set;
}
///
/// 当前用户ID
///

string UserID
{
get;
set;
}
}
复制代码

第二:定义一个上下文句柄接口,用于获取和重置上下文。


public interface IContextHandler
{
///
/// 获取上下文
///

/// 返回当前上下文
IContext GetContext();

///
/// 设置当前上下文
///

void SetContext(IContext context);
}
复制代码


第三:定义上下文的通用实现类,基本思想就是在请求产生后,获取请求相关信息,将这些信息存储在HttpContext.Current.Items中。



View Code
public class CommonContextHandler : IContextHandler
{
private static readonly string _ContextDataName = "#CurrentContext#";

[ThreadStatic]
private static IContext _ContextInstance;

public CommonContextHandler()
{

}

#region IContextHandler Members

public IContext GetContext()
{

if (HttpContext.Current == null)
{
if (_ContextInstance == null)
{
_ContextInstance = CreateNewContext();
}

return _ContextInstance;
}
else
{
object obj = HttpContext.Current.Items[_ContextDataName];
if (obj == null)
{
HttpContext.Current.Items[_ContextDataName] = CreateNewContext();
obj = HttpContext.Current.Items[_ContextDataName];
}

return (IContext)obj;
}
}

public void SetContext(IContext context)
{
if (HttpContext.Current == null)
{
_ContextInstance = context;
}
else
{
object obj = HttpContext.Current.Items[_ContextDataName];
if (obj == null)
{
HttpContext.Current.Items[_ContextDataName] = context;
}
else
{
HttpContext.Current.Items[_ContextDataName] = context;
}
}
}

#endregion

#region 保护方法

protected virtual IContext CreateNewContext()
{
return new CommonContext();
}

#endregion
}
复制代码

第四:编写一个适用于web程序的上下文实体类,主要是为上下文实体类填充数据,以借记录数据时使用。


View Code
[Serializable]
public class SimpleWebContext : IContext
{
#region 私有成员

private Guid _UniqueID;
private string _Re
首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MongoDB学习(三)MongoDB shell命.. 下一篇MongoDB学习(一)安装配置

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis on AWS:Elast (2025-12-27 04:19:30)
·在 Spring Boot 项目 (2025-12-27 04:19:27)
·使用华为开发者空间 (2025-12-27 04:19:24)
·Getting Started wit (2025-12-27 03:49:24)
·Ubuntu 上最好用的中 (2025-12-27 03:49:20)