【问题标题】:Failed to map the path '/' with asp.net development server无法将路径“/”映射到 asp.net 开发服务器
【发布时间】:2013-10-01 11:29:49
【问题描述】:

我使用以下代码在运行时更改 web.config

Configuration conf = WebConfigurationManager.OpenWebConfiguration("~/");
conf.ConnectionStrings.ConnectionStrings["ApplicationServices"].ConnectionString = "Test";
    conf.Save();

但我收到一个错误 - “无法映射路径 '/'。”我在互联网上搜索并研究了所有解决方案,例如 1.将路径改为“/” 2.将路径改为“~/”

但同样的问题发生了。有一点我想说的是,我的应用程序不是托管在 IIS 上,而是使用 asp.net 开发服务器通过视觉工作室运行

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    ~ 替换为HttpContext.Current.Request.ApplicationPath

    Configuration conf = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath)

    ~ 应该可以工作,我建议ApplicationPath 确保托管在 IIS 而不是 VS DevServer 上时的虚拟目录差异。

    事实上,如果你在root中定位web.config,那么你只需要传递null作为参数。无需传递~

    编辑:

    您是否使用管理权限?要在 VS Development Server 上运行,您必须以管理员权限启动 Visual Studio。右键单击 Visual Studio 和 Run As Administrator

    【讨论】:

    • 嗨,我仍然面临同样的问题
    • 嗨,我在 内的 web.config 中又做了一个补充,因为我在一个线程中读到这个设置应该在 IIS 中启用。因此,为了为单个应用程序启用此设置,我在 web.config 中完成了此更改
    • 使用 Run As Adminstrator 启动 Visual Studio。更新了我的答案。
    • 非常感谢。但我不知道如何将此评论作为答案
    • 确实,HttpContext.Current.Request.ApplicationPath 在开发期间和部署到 IIS 时都有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-09
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多