Behing update web.config code update

I, from the code I need, should update my web.config. This has never been a problem before, however I am getting an error recently. The errors say: "Failed to map path //". The lines commented out were different versions 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();
+3
source share
4 answers

I found out the cause of the error. After moving the site from my local C: drive to the western digital passport and launching the application, the error started. The line of code is below:

Configuration myWebConfig = WebConfigurationManager.OpenWebConfiguration("~/");
+3
source

WebConfigurationManager.OpenWebConfiguration( "." ); , web.config

WebConfigurationManager.OpenWebConfiguration( "web.config" );

, .

+1

"~/" -. "~" null ; "" (.. bin) .

+1

This happened to me when I switched from Windows Vista to Windows 7. By default for Windows 7, this caused this because VS did not have permission to open the file. I just restarted Visual Studio as an administrator, and it worked just as easily. Hope this helps some other people.

0
source

Source: https://habr.com/ru/post/1718073/


All Articles