Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Behing update web.config mapping issue

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();
like image 353
aron Avatar asked Feb 22 '26 08:02

aron


1 Answers

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("~/");
like image 148
aron Avatar answered Feb 23 '26 22:02

aron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!