AspNet_RegIIS ...encrypting web.config when running Cassini

H

Hey it's Filippo

ASP.NET 2.0
Windows app written in C# and VS 2005
=============================
I am having difficulties encryting web.config files when using Cassini (IIS is currenly disabled) as the VirtualDirectory param seems to only work when IIS is up and running.
The idea is that we want our windows app, that uses a browser component to run local sites, to work on OS that don't have IIS. So we need to embed Cassini in order to make it work.

And all works perfectly ...all but the call to encrypt the web.config.
I am trying 2 different techniques:
1) Configuration object
FileAttributes attr = FileAttributes.Archive | FileAttributes.Normal;
File.SetAttributes(Constant.FolderWebsite + @"\Web.Config", attr);
Configuration config = WebConfigurationManager.OpenWebConfiguration("/MyWebSiteVirtualDir");
ConnectionStringsSection section = config.GetSection("connectionStrings") as ConnectionStringsSection;
if (section.SectionInformation.IsProtected == false)
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();


2) Run a command using AspNet_RegIIS
string param = "-pe \"connectionStrings\" -app \"/MyWebSiteVirtualDir\" -prov \"DataProtectionConfigurationProvider\"";
Process myProcess = new Process();
object o = new object();
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.FileName = "aspnet_regiis";
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(o.GetType().Assembly.Location);
myProcess.StartInfo.Arguments = param;
myProcess.Start();
myProcess.WaitForExit();
myProcess.Close();


Both techniques work when IIS is up and running because it returns the physical path of the MyWebSiteVirtualDir.

QUESTION
How can I make this working when IIS is not present?
Is there a different way to encrypt a web config without having the need of IIS?


Thanks,
Filippo
 
D

Dominick Baier

for the command line use -pef.

for the API - create a Map (have a look at the overloads of OpenWebConfiguration)
- this allows to map vdirs to physical dirs.
 
H

Hey it's Filippo

Thanks Dominick !!!


SOLUTION
============================================================
FileAttributes attr = FileAttributes.Archive | FileAttributes.Normal;
File.SetAttributes(Constant.FolderWebsite + @"\Web.Config", attr);
WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
VirtualDirectoryMapping vDir = new
VirtualDirectoryMapping(Constant.FolderWebsite, false);
fileMap.VirtualDirectories.Add(Constant.IISOfflineVirtualPath, vDir);

Configuration config =
WebConfigurationManager.OpenMappedWebConfiguration(fileMap,
Constant.IISOfflineVirtualPath);

ConnectionStringsSection section = config.GetSection("connectionStrings") as
ConnectionStringsSection;

if (section.SectionInformation.IsProtected == false)
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");

// ** To Unprotected
// section.SectionInformation.UnprotectSection();

config.Save();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top