说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能映射路径“/”。源错误: 
行 17:         private static readonly ISiteSetting site = DataAccess.CreateSiteSetting();
行 18: 
行 19:         private static readonly Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
行 20: 
行 21:         public static SiteSettings GetSiteSettings(string applicationName)
 源文件: D:\JiaEN\BLL\SiteSetting.cs    行: 19 堆栈跟踪: 
[InvalidOperationException: 未能映射路径“/”。]
   System.Web.Configuration.ProcessHostConfigUtils.MapPathActual(String siteName, VirtualPath path) +253
   System.Web.Configuration.ProcessHostMapPath.MapPathCaching(String siteID, VirtualPath path) +669
   System.Web.Configuration.ProcessHostMapPath.GetPathConfigFilenameWorker(String siteID, VirtualPath path, String& directory, String& baseName) +19
   System.Web.Configuration.ProcessHostMapPath.System.Web.Configuration.IConfigMapPath.GetPathConfigFilename(String siteID, String path, String& directory, String& baseName) +37
   System.Web.Configuration.HostingPreferredMapPath.GetPathConfigFilename(String siteID, String path, String& directory, String& baseName) +75
   System.Web.Configuration.WebConfigurationHost.GetStreamName(String configPath) +8845430
   System.Configuration.Internal.DelegatingConfigHost.GetStreamName(String configPath) +13
   System.Configuration.BaseConfigurationRecord.InitConfigFromFile() +154[ConfigurationErrorsException: 加载配置文件时出错: 未能映射路径“/”。]
   System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) +650948
   System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) +31
   System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams) +356
   System.Configuration.Internal.InternalConfigConfigurationFactory.System.Configuration.Internal.IInternalConfigConfigurationFactory.Create(Type typeConfigHost, Object[] hostInitConfigurationParams) +29
   System.Web.Configuration.WebConfigurationHost.OpenConfiguration(WebLevel webLevel, ConfigurationFileMap fileMap, VirtualPath path, String site, String locationSubPath, String server, String userName, String password, IntPtr tokenHandle) +775
   System.Web.Configuration.WebConfigurationManager.OpenWebConfigurationImpl(WebLevel webLevel, ConfigurationFileMap fileMap, String path, String site, String locationSubPath, String server, String userName, String password, IntPtr userToken) +84
   System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(String path) +36
   Jiaen.BLL.SiteSetting..cctor() in D:\JiaEN\BLL\SiteSetting.cs:19[TypeInitializationException: “Jiaen.BLL.SiteSetting”的类型初始值设定项引发异常。]
   Jiaen.BLL.SiteSetting.GetSiteSettings(String applicationName) in D:\JiaEN\BLL\SiteSetting.cs:24
   Jiaen.Controls.SiteImage..ctor() in D:\JiaEN\Controls\SiteImage.cs:24
   ASP.control_viewdefaultbanner_ascx.__BuildControlSiteImage1() in d:\JiaEN\web\Control\ViewDefaultBanner.ascx:18
   ASP.control_viewdefaultbanner_ascx.__BuildControlTree(control_viewdefaultbanner_ascx __ctrl) in d:\JiaEN\web\Control\ViewDefaultBanner.ascx:1
   ASP.control_viewdefaultbanner_ascx.FrameworkInitialize() in d:\JiaEN\web\Control\ViewDefaultBanner.ascx.cs:912307
   System.Web.UI.UserControl.InitializeAsUserControlInternal() +35
   System.Web.UI.UserControl.InitializeAsUserControl(Page page) +14
   ASP.templete2_master.__BuildControlViewDefaultBanner1() in d:\JiaEN\web\Templete2.master:13
   ASP.templete2_master.__BuildControlform1() in d:\JiaEN\web\Templete2.master:10
   ASP.templete2_master.__BuildControlTree(templete2_master __ctrl) in d:\JiaEN\web\Templete2.master:1
   ASP.templete2_master.FrameworkInitialize() in d:\JiaEN\web\Templete2.master.cs:912308
   System.Web.UI.UserControl.InitializeAsUserControlInternal() +35
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +8669695
   System.Web.UI.Page.get_Master() +51
   System.Web.UI.Page.ApplyMasterPage() +15
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282 请高手帮忙解决

解决方案 »

  1.   

    试一下:
    System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
    web.config是标准的xml文件,建议你直接using System.Xml;
    后,按照xml操作。
    这个。
    Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath); //创建配置文件对象
    config.AppSettings.Settings["RecEmail"].Value = txtEmail.Text; //设置KEY的值为VALUE
    config.Save(ConfigurationSaveMode.Modified); //保存设置
    ConfigurationManager.RefreshSection("appSettings"); //刷新设置
      

  2.   

    1.用'//'代替'/'
    2.或者是@+路径 
    3.或者是如下情况   String strPhysicalDir = MyComputer.FileSystem.GetParentPath(Server.MapPath("/css"));
    改为"~/css"问题解决4.或者是IIS有问题,重新装IIS就可以。
    5.或者,您可以把可能出错误的代码贴一下吗?这个问题可能由多个原因引起,后面的人可以更准确的分析。
      

  3.   

    Server.MapPath(Request.ApplicationPath);
    检查权限
      

  4.   

    你可以在global.asax request begin方法内面对HttpContext.Current里面的类一些属性进行测试,比如HttpContext.Current.Request.ApplicationPath,如不能获得该值,请检查你的.net framework版本是否正确,你有没有启用域名访问,你的IIS当前进程用户能否访问该地址等等。
      

  5.   

    估计楼主是环境配置的问题。
    建议楼主编译完成后发布在IIS上看看。
      

  6.   

    已解决,并非Server.MapPath的问题,是权限问题。 
    问题原因:我使用的是win7系统,在打开项目的时候,并非使用的是管理员身份。 
    解决方式:用管理员身份进入vs2008,为程序目录设置erveryone 的所有权限。---调试正常。 转自:http://topic.csdn.net/u/20091010/12/7d71f22f-5b7b-4fb8-ad2d-d7e503a03f7e.html
      

  7.   


    真的是我WIN7的权限问题! 问题已解决! 谢谢这位老兄,分给你了!
      

  8.   

    我找到解决方法了,和大家分享一下:
    问题:未能映射路径“/”。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能映射路径“/”。
    解决:在webconfig 文件里有这个: <add key="Page.SitePath" value="/"/>
    我们只需去掉value="/"中的 “/”  就ok啦
      

  9.   

    我的项目里面也出现这种情况,我的也是WIN7 ,将网站配到IIS里面就报这个错。郁闷。如果是直接加到解决方案里面运行时没问题,难道是IIS的限制,因为在配置这个报错的网站之前,我已近配置了5个站点,都没有这个问题,配置第六个的时候,就出现这个问题。
    配置文件中,我也找不到<add key="Page.SitePath" value="/"/>
    这个节点。
    求助,文件夹权限已经给到最大了。
      

  10.   

    14楼的,解决没有啊,我也遇到这种问题了,原本配置2个站点都是好的,到第三个的时候就遇到这种问题了,也搞不懂为什么,对了我的环境是.net Framework 4.0 经典,郁闷啊