DotText缺少Global.asax会出现什么情况?!
2005-10-28 17:49 无常 阅读(1360) 评论(1) 编辑 收藏 举报
曾经在这里发过这篇POST《求助:GetVaryByCustomString()不工作》
但没有人回答,google和baidu都没有答案
昨天看了dudu的《搜索引擎, 请手下留情》之后
我也想给统计一下二频博客的访问者
在Global.asax.cs中
我在部署时也没去检查
呵呵
问题终于解决了
但没有人回答,google和baidu都没有答案
昨天看了dudu的《搜索引擎, 请手下留情》之后
我也想给统计一下二频博客的访问者
在Global.asax.cs中
public class Global : System.Web.HttpApplication
{
public static System.Collections.Hashtable htBrowser = new Hashtable();
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string userAgent = Context.Request.UserAgent;
//Context.Request.UserAgent
//Application.Lock(); 反正要求精度不高,为了尽量不影响性能,不用锁了
if( htBrowser.Contains(userAgent) )
{
int c = Convert.ToInt32(htBrowser[userAgent].ToString());
htBrowser[userAgent] = c+1;
}else
{
htBrowser.Add(userAgent,1);
}
//Application.UnLock();
}
}
新加一个test.aspx {
public static System.Collections.Hashtable htBrowser = new Hashtable();

protected void Application_BeginRequest(Object sender, EventArgs e)
{
string userAgent = Context.Request.UserAgent;
//Context.Request.UserAgent
//Application.Lock(); 反正要求精度不高,为了尽量不影响性能,不用锁了
if( htBrowser.Contains(userAgent) )
{
int c = Convert.ToInt32(htBrowser[userAgent].ToString());
htBrowser[userAgent] = c+1;
}else
{
htBrowser.Add(userAgent,1);
}
//Application.UnLock();
}

}
private void Page_Load(object sender, System.EventArgs e)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<table border=\"1\" cellpadding=\"5\"><tr>");
sb.Append("<td>Browser</td><td>Count</td>");
System.Collections.IDictionaryEnumerator ide = Dottext.Global.htBrowser.GetEnumerator();
while (ide.MoveNext())
{
sb.Append(string.Format( "<tr><td>{0}</td><td>{1}</td></tr>", ide.Key, ide.Value) );
}
sb.Append("</tr></table>");
Response.Write( sb.ToString();
}
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<table border=\"1\" cellpadding=\"5\"><tr>");
sb.Append("<td>Browser</td><td>Count</td>");
System.Collections.IDictionaryEnumerator ide = Dottext.Global.htBrowser.GetEnumerator();
while (ide.MoveNext())
{
sb.Append(string.Format( "<tr><td>{0}</td><td>{1}</td></tr>", ide.Key, ide.Value) );
}
sb.Append("</tr></table>");
Response.Write( sb.ToString();
}
在本机测试成功,但上传到服务器后就不工作了
test.aspx总是没内容
百思不得其解
这让我想起以缓存不更新的事
突然想到会不会是Application_BeginRequest根本不执行呢
那又是为什么会不执行这段代码
灵感一现
看了一下服务器上的文件,果然是没有Global.asax
把这个文件上传,OK!
包括以前自定义缓存的问题也解决了
回顾一下问题的原因
因为我用了一个build.bat批处理,把CNBlogsDottext目录中的需要部署的文件都拷贝出来
@echo off
echo - Copying Web Files
xcopy *.gif ..\builds\release\web\ /s /y /q
xcopy *.jpg ..\builds\release\web\ /s /y /q
xcopy *.txt ..\builds\release\web\ /s /y /q
xcopy *.aspx ..\builds\release\web\ /s /y /q
xcopy *.ascx ..\builds\release\web\ /s /y /q
xcopy *.htm* ..\builds\release\web\ /s /y /q
xcopy *.xml ..\builds\release\web\ /s /y /q
xcopy *.css ..\builds\release\web\ /s /y /q
xcopy *.js ..\builds\release\web\ /s /y /q
xcopy bin\*.dll ..\builds\release\web\bin\ /s /y /q
xcopy *.config ..\builds\release\web\ /s /y /q
xcopy *.xsl ..\builds\release\web\ /s /y /q
但这个批处理里没有把*.asax拷出来echo - Copying Web Files

xcopy *.gif ..\builds\release\web\ /s /y /q
xcopy *.jpg ..\builds\release\web\ /s /y /q
xcopy *.txt ..\builds\release\web\ /s /y /q
xcopy *.aspx ..\builds\release\web\ /s /y /q
xcopy *.ascx ..\builds\release\web\ /s /y /q
xcopy *.htm* ..\builds\release\web\ /s /y /q
xcopy *.xml ..\builds\release\web\ /s /y /q
xcopy *.css ..\builds\release\web\ /s /y /q
xcopy *.js ..\builds\release\web\ /s /y /q
xcopy bin\*.dll ..\builds\release\web\bin\ /s /y /q
xcopy *.config ..\builds\release\web\ /s /y /q
xcopy *.xsl ..\builds\release\web\ /s /y /q
我在部署时也没去检查
呵呵
问题终于解决了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架