DotText缺少Global.asax会出现什么情况?!
2005-10-28 17:49
507 查看
曾经在这里发过这篇POST《求助:GetVaryByCustomString()不工作》
但没有人回答,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
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();
}
在本机测试成功,但上传到服务器后就不工作了
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拷出来
我在部署时也没去检查
呵呵
问题终于解决了
但没有人回答,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
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();
}
在本机测试成功,但上传到服务器后就不工作了
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拷出来
我在部署时也没去检查
呵呵
问题终于解决了
相关文章推荐
- 数据库并发情况下什么情况会出现脏读,如何防范脏读
- Android系统中GC什么情况下会出现内存泄露?
- 手机调用系统的拍照和裁剪功能,如果界面有输入框EditText,在一些手机会出现点击EditText会弹出输入法,却不能输入的情况。
- Global.asax 文件是什么
- Global.asax 文件是什么
- Global.asax 文件是什么
- Global.asax 文件是什么
- . Android系统中GC什么情况下会出现内存泄露呢?
- ASP.NET-Global.asax 文件是什么?
- Global.asax 文件是什么
- Android中EditText在ListView中会出现消失的情况
- Global.asax 文件是什么
- Fortran 当数组大小不一样时,会出现什么情况。
- 数组越界场景集合(什么情况会出现数组越界呢)--iOS开发
- 手机调用系统的拍照和裁剪功能,假设界面有输入框EditText,在一些手机会出现点击EditText会弹出输入法,却不能输入的情况。
- Global.asax 文件是什么
- 面试中遇到的问题:一个指针重复释放会出现什么情况
- 两个线程同时调用一个函数会出现什么情况?
- Global.asax 文件是什么
- poi导出execl的时候,如果不点击保存或其他按钮,会出现什么情况?