DotText缺少Global.asax会出现什么情况?!
2005-10-28 17:49 无常 阅读(1365) 评论(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
我在部署时也没去检查
呵呵
问题终于解决了
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号