在windows应用程序中运行asp.net程序的下级目录问题

重载SimpleWorkerRequest


为了能运行下级目录的aspx文件,我们不能象解决中文乱码的方式重载,需要重写重多的方法。当然我也不清楚需要重写哪些方法,我想当然的重写了几个方法后,依然不然,最后只好让Cassini来告诉我了。当然让她告诉我,我只好耐心的在几乎每个方法上添加Trace.WriteLine方法。我得到了以下"提示":



[3]Process...
[4]MapPath(String path="/mag/Maintain/AdList.aspx") should return D:\Magazine\Mag.Web.App\Maintain\AdList.aspx...
[5]GetAppPath() should return /mag
[6]MapPath(String path="/mag") should return D:\Magazine\Mag.Web.App...
[7]MapPath(String path="") should return C:\WINDOWS\system32...
[8]GetAppPath() should return /mag
[9]GetAppPath() should return /mag
[10]GetFilePath() should return /mag/Maintain/AdList.aspx
[11]MapPath(String path="/mag/Maintain/AdList.aspx") should return D:\Magazine\Mag.Web.App\Maintain\AdList.aspx...
[12]MapPath(String path="/mag/Maintain") should return D:\Magazine\Mag.Web.App\Maintain...
[13]GetAppPath() should return /mag
[14]MapPath(String path="/mag/Maintain/AdList.aspx") should return D:\Magazine\Mag.Web.App\Maintain\AdList.aspx...
[15]GetAppPathTranslated() should return D:\Magazine\Mag.Web.App\
"141cf04": 已加载"c:\windows\assembly\gac\system.web.regularexpressions\1.0.5000.0__b03f5f7f11d50a3a\system.web.regularexpressions.dll",未加载符号。
[16]GetAppPath() should return /mag
....
[20]MapPath(String path="/mag/global.asax") should return D:\Magazine\Mag.Web.App\global.asax...
...
[24]MapPath(String path="") should return C:\WINDOWS\system32...
[25]GetAppPathTranslated() should return D:\Magazine\Mag.Web.App\
...
[29]GetUriPath() should return /mag/Maintain/AdList.aspx
[30]GetFilePathTranslated() should return D:\Magazine\Mag.Web.App\Maintain\AdList.aspx
[31]MapPath(String path="/mag/Maintain") should return D:\Magazine\Mag.Web.App\Maintain...
[32]MapPath(String path="/mag/Maintain/CustomServiceList.aspx") should return D:\Magazine\Mag.Web.App\Maintain\CustomServiceList.aspx...
...
"141cf04": 已加载"c:\windows\assembly\gac\mscorlib.resources\1.0.5000.0_zh-chs_b77a5c561934e089\mscorlib.resources.dll",未加载符号。
"141cf04": 已加载"c:\windows\assembly\gac\system.data.resources\1.0.5000.0_zh-chs_b77a5c561934e089\system.data.resources.dll",未加载符号。
[65]SendResponseFromMemory...
[66]SendResponseFromMemory...
[67]SendResponseFromMemory...
[68]FlushResponse...
[69]SendResponseFromMemory...
[70]FlushResponse...


省略了一些输出,大家可以留意一下以"[数字]"开头的行。于是我就有了足够的信息去重写了,为了方便测试,我因应我的环境,固定了两个变量

/// <summary> 
/// 测试用。asp.net应用程序所在的目录 
/// </summary> 

public const string APP_FOLD = @"D:\Magazine\Mag.Web.App"
/// <summary> 
/// 测试用。asp.net的虚拟应用程序名 
/// </summary> 

public const string APP_VIRT = "/foo";

以下是完整的代码

    public class MyRequest:SimpleWorkerRequest 
    
{
        
/// <summary>
        
/// 测试用。asp.net应用程序所在的目录
        
/// </summary>

        public const string APP_FOLD = @"D:\Magazine\Mag.Web.App";
        
/// <summary>
        
/// 测试用。asp.net的虚拟应用程序名
        
/// </summary>

        public const string APP_VIRT = "/foo";

        
private string _filePath;
        
private string _path;
        
        
private ArrayList        _responseBodyBytes;
        
private FileStream        _file;
        
private System.IO.MemoryStream mem;
        
private System.IO.StreamWriter writer;
        
public MyRequest(string pWebPage, string pQuery,string pFile):base(String.Empty,pQuery,null)
        
{
            
this.mem = new MemoryStream();

//            this.writer = new StreamWriter(pFile,false,Encoding.GetEncoding("gb2312"));
            this.writer = new StreamWriter(pFile,false,Encoding.UTF8);
            
this._responseBodyBytes = new ArrayList();
            
this.initFilePath(pWebPage);
        }


        
private void initFilePath(string path)
        
{
            
this._path = path;            
            
string str = string.Format("{0}\\{1}",APP_FOLD, path);            
            str 
= str.Replace("/","\\");
            
this._filePath = str;    
        }


        
重写HttpWorkerRequest相关方法
        
    }

 

 

posted @ 2006-06-07 14:10  生命体验之kevin-Y  阅读(715)  评论(0编辑  收藏  举报