新建一个类库,在这个类库里如何判断当前使用这个类库的是一个web应用程序,还是exe程序呢?

解决方案 »

  1.   

    调用系统的CMD.EXE,可执行文件会有执行结果,不是可执行文件会报错
      

  2.   

    可以试一下在这个类库里判断 AppDomain.CurrentDomain.BaseDirectory 是否含有"http://"
      

  3.   

    含有"http://" 的是web,不含有的是exe
      

  4.   

    在APP里写个东西算了,搞这么麻烦
      

  5.   

    不好意思,测了一下,我上面的方法行不通,web下调用,AppDomain.CurrentDomain.BaseDirectory 也是c:\intput\...这种形式的
      

  6.   

    AppDomain.CurrentDomain.BaseDirectory 得到的还是物理路径,没有http:
      

  7.   

    不知道这样是否满足要求?判断直接调用此类库的程序文件的后缀。
    public string  getAppType()
    {
         Assembly asm = Assembly.GetCallingAssembly();
         string vsName = asm.CodeBase;
         string vsLast = vsName.Substring(vsName.LastIndexOf(".")+1);
         if(vsLast=="exe")
    return "exe";
         else
    return "web";
    }
      

  8.   

    To :wumingxiaodi(无名小弟) 
    你这个方法也不行啊,因为我这是一个类库,Assembly.GetCallingAssembly().CodeBase得到的是类库的路径,而不是调用这个类库的程序的名称。