private static string LogPath = "E:/VSS_Content/dev/crm/source/CrmHr.root/CrmHr/WebSite/Log";上面一句,直接赋值,没有错误
private static string LogPath = HttpContext.Current.Server.MapPath("~/" + "Log").Replace("\\","/");
private static string LogPath = HttpContext.Current.Server.MapPath("~/" + "Log");这两句,都产生错误了
而在页面代码中,调试得到的变量值分别如下:
E:\VSS_Content\dev\crm\source\CrmHr.root\CrmHr\WebSite\Log
E:/VSS_Content/dev/crm/source/CrmHr.root/CrmHr/WebSite/Log
为何在逻辑层代码的类变量定义中,这样声明就错误呢?

解决方案 »

  1.   

    错误提示:
    "Logics.ClassAlarm”的类型初始值设定项引发异常请教各位了。
      

  2.   

    逻辑层中能得到HttpContext 到不
      

  3.   

    HttpContext.Current是实例对象,只能用于HTTP Request...静态变量是实例无关的...
      

  4.   

    只能用于HTTP Request => 只能用于HTTP Request上下文...
      

  5.   

    到MSDN上了解一下HttpContext.Current
      

  6.   

    楼主试试这个
    public static string LogPath
        {
            get
            {
                return HttpContext.Current.Server.MapPath("~/" + "Log").Replace("\\", "/");
            }
        }