G
Guest
I am looking for a way to programatically change the .net version of the
virtual directory that I am creating within a aspx page.
As part of creating a new customer in my asp.net 2 application, it
automatically creates a virtual directory and configures it. I am using the
DirectoryServices.DirectoryEntry class in C# to do this. I am unable to set
the .Net version of the virtual directory from 1.1 to version 2. All searches
led me to the aspnet_regiis.exe. I tried 2 different solutions:-
----------------------------------------------------------------------
1. Call aspnet_regiis.exe -s W3SVC/1/root/vdirname from my aspx page after
creating the virtual directory. It fails because the process is running as
'NETWORK SERVICE' user who does not have enough permission to do these. When
I changed the identity of the Application Pool from 'Network Service' to
'Local System', I could run successfully change the version using
aspnet_regiis.exe
//Code in aspx page
string strFrameworkVersion =
ConfigurationManager.AppSettings["frameworkVersion"];
string winPath = Environment.GetEnvironmentVariable("windir");
string fullPath = winPath + @"\Microsoft.NET\Framework\v" +
strFrameworkVersion + @"\aspnet_regiis.exe";
string args = " -s " + "W3SVC/1/root/" + nameDirectory;
ProcessStartInfo startInfo = new ProcessStartInfo(fullPath);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
System.Diagnostics.Process process = new System.Diagnostics.Process();
startInfo.Arguments = args;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
---------------------------------------------------------------
2. I tried to modify the scriptmap programatically to match what
aspnet_regiis.exe does, i.e. changes the path to the right version of .NET.
But that made no difference. In fact, after running this code, the virtual
directory had no version of .NET selected.
PropertyValueCollection vals = siteVDir.Properties["ScriptMaps"];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersion =
ConfigurationManager.AppSettings["frameworkVersion"];
foreach (string val in vals)
{
if (val.Contains("Framework"))
{
string version = val.Substring(val.IndexOf("Framework")
+ 10, 9);
if(version != frameworkVersion)
{
objScriptMaps.Add( val.Replace(version,
frameworkVersion));
}
}
else
{
objScriptMaps.Add(val);
}
}
siteVDir.Properties["ScriptMaps"].Value =
objScriptMaps.ToArray();
siteVDir.CommitChanges();
------------------------------------------
What is the most appropriate way to change the .NET version of the created
virtual directory, programatically from within as aspx page?
Thanks
Rakesh
virtual directory that I am creating within a aspx page.
As part of creating a new customer in my asp.net 2 application, it
automatically creates a virtual directory and configures it. I am using the
DirectoryServices.DirectoryEntry class in C# to do this. I am unable to set
the .Net version of the virtual directory from 1.1 to version 2. All searches
led me to the aspnet_regiis.exe. I tried 2 different solutions:-
----------------------------------------------------------------------
1. Call aspnet_regiis.exe -s W3SVC/1/root/vdirname from my aspx page after
creating the virtual directory. It fails because the process is running as
'NETWORK SERVICE' user who does not have enough permission to do these. When
I changed the identity of the Application Pool from 'Network Service' to
'Local System', I could run successfully change the version using
aspnet_regiis.exe
//Code in aspx page
string strFrameworkVersion =
ConfigurationManager.AppSettings["frameworkVersion"];
string winPath = Environment.GetEnvironmentVariable("windir");
string fullPath = winPath + @"\Microsoft.NET\Framework\v" +
strFrameworkVersion + @"\aspnet_regiis.exe";
string args = " -s " + "W3SVC/1/root/" + nameDirectory;
ProcessStartInfo startInfo = new ProcessStartInfo(fullPath);
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
System.Diagnostics.Process process = new System.Diagnostics.Process();
startInfo.Arguments = args;
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
---------------------------------------------------------------
2. I tried to modify the scriptmap programatically to match what
aspnet_regiis.exe does, i.e. changes the path to the right version of .NET.
But that made no difference. In fact, after running this code, the virtual
directory had no version of .NET selected.
PropertyValueCollection vals = siteVDir.Properties["ScriptMaps"];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersion =
ConfigurationManager.AppSettings["frameworkVersion"];
foreach (string val in vals)
{
if (val.Contains("Framework"))
{
string version = val.Substring(val.IndexOf("Framework")
+ 10, 9);
if(version != frameworkVersion)
{
objScriptMaps.Add( val.Replace(version,
frameworkVersion));
}
}
else
{
objScriptMaps.Add(val);
}
}
siteVDir.Properties["ScriptMaps"].Value =
objScriptMaps.ToArray();
siteVDir.CommitChanges();
------------------------------------------
What is the most appropriate way to change the .NET version of the created
virtual directory, programatically from within as aspx page?
Thanks
Rakesh