code Behing更新web.config文件映射问题 [英] Code Behing update web.config mapping issue
本文介绍了code Behing更新web.config文件映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从code后面,我需要更新我的web.config。这从来就不是一个问题之前,但我最近得到一个错误。错误说无法映射路径'/'。
该行注释掉是什么,我尝试了不同的变化。
//配置myWebConfig = WebConfigurationManager.OpenWebConfiguration(使用Server.Mappath(〜));
//配置myWebConfig = WebConfigurationManager.OpenWebConfiguration(〜);
//配置myWebConfig = WebConfigurationManager.OpenWebConfiguration(NULL);
配置myWebConfig = WebConfigurationManager.OpenWebConfiguration(。);
//更新页面的主题
RoleManagerSection部分=(RoleManagerSection)myWebConfig.GetSection(的System.Web / roleManager);
section.DefaultProvider =SqlRoleManager;
section.Providers.Clear();
ProviderSettings providerSettings =新ProviderSettings();
providerSettings.Name =SqlRoleManager;
providerSettings.Type =System.Web.Security.SqlRoleProvider;
providerSettings.Parameters.Clear();
providerSettings.Parameters.Add(的connectionStringName,SimpleTickConnection);
providerSettings.Parameters.Add(的applicationName,TheaterSales);
section.Providers.Add(providerSettings);
myWebConfig.Save();
解决方案
我想通了错误的原因。从我的本地C移动网站后:驱动器西部数据的护照和运行应用程序启动的错误。 code以下的线路是好的:
配置myWebConfig = WebConfigurationManager.OpenWebConfiguration(〜/);
I from the code behind I need to update my web.config. This has never been a problem before, however I am getting an error recently. The errors say "Failed to map the path '/'." The lines commented out were different variations of what i tried.
//Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(Server.MapPath("~"));
//Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~");
//Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(null);
Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration(".");
// update pages theme
RoleManagerSection section = (RoleManagerSection)myWebConfig.GetSection("system.web/roleManager");
section.DefaultProvider = "SqlRoleManager";
section.Providers.Clear();
ProviderSettings providerSettings = new ProviderSettings();
providerSettings.Name = "SqlRoleManager";
providerSettings.Type = "System.Web.Security.SqlRoleProvider";
providerSettings.Parameters.Clear();
providerSettings.Parameters.Add("connectionStringName", "SimpleTickConnection");
providerSettings.Parameters.Add("applicationName", "TheaterSales");
section.Providers.Add(providerSettings);
myWebConfig.Save();
解决方案
I figured out the reason for the error. After moving the site from my local C: drive to a western digital passport and running the app the error started. The line of code below is fine:
Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
这篇关于code Behing更新web.config文件映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文