A
Alex. O. Koranteng
I am getting the error mesage indicated below when my code code hits the line
Configuration config = WebConfigurationManager.OpenWebConfiguration----
I am calling this class from a button on my page as shown below. Any
suggestions/help will be appreciated
using System;
using System.Web.Configuration;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class EncDecWebConfig : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// load web.config into TextBox on first page visit...
if (!Page.IsPostBack)
{
RefreshWebConfig();
}
}
private void RefreshWebConfig()
{
// Read in the value of Web.config into the TextBox...
//using (StreamReader reader =
File.OpenText(Server.MapPath("~/Web.config")))
using (StreamReader reader =
File.OpenText(Server.MapPath("~/Web.config")))
{
webConfig.Text = reader.ReadToEnd();
}
// Programmatically read in the value of the connection string
PlainTextConnectionString.Text =
ConfigurationManager.ConnectionStrings["MembershipConnectionString"].ConnectionString;
}
protected void btnRefreshWebConfig_Click(object sender, EventArgs e)
{
RefreshWebConfig();
}
protected void btnEncrypt_Click(object sender, EventArgs e)
{
ProtectSection("connectionStrings",
"DataProtectionConfigurationProvider");
RefreshWebConfig();
}
public void ProtectSection(string sectionName,
string provider)
{
Configuration config =
WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(sectionName);
if (section != null &&
!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}
}
Server Error in '/EncConfig1' Application.
--------------------------------------------------------------------------------
Failed to map the path '/'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Failed to map the path
'/'.
Source Error:
Line 73: string provider)
Line 74: {
Line 75: Configuration config =
Line 76: WebConfigurationManager.
Line 77: OpenWebConfiguration(Request
Configuration config = WebConfigurationManager.OpenWebConfiguration----
I am calling this class from a button on my page as shown below. Any
suggestions/help will be appreciated
using System;
using System.Web.Configuration;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class EncDecWebConfig : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// load web.config into TextBox on first page visit...
if (!Page.IsPostBack)
{
RefreshWebConfig();
}
}
private void RefreshWebConfig()
{
// Read in the value of Web.config into the TextBox...
//using (StreamReader reader =
File.OpenText(Server.MapPath("~/Web.config")))
using (StreamReader reader =
File.OpenText(Server.MapPath("~/Web.config")))
{
webConfig.Text = reader.ReadToEnd();
}
// Programmatically read in the value of the connection string
PlainTextConnectionString.Text =
ConfigurationManager.ConnectionStrings["MembershipConnectionString"].ConnectionString;
}
protected void btnRefreshWebConfig_Click(object sender, EventArgs e)
{
RefreshWebConfig();
}
protected void btnEncrypt_Click(object sender, EventArgs e)
{
ProtectSection("connectionStrings",
"DataProtectionConfigurationProvider");
RefreshWebConfig();
}
public void ProtectSection(string sectionName,
string provider)
{
Configuration config =
WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section =
config.GetSection(sectionName);
if (section != null &&
!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}
}
Server Error in '/EncConfig1' Application.
--------------------------------------------------------------------------------
Failed to map the path '/'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Failed to map the path
'/'.
Source Error:
Line 73: string provider)
Line 74: {
Line 75: Configuration config =
Line 76: WebConfigurationManager.
Line 77: OpenWebConfiguration(Request