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 8 7741
You can check this site out: http://www.denisbauer.com/NETTools/A...nSwitcher.aspx
"Rak" wrote: 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
Thanks for the response, but I need to do this programatically from withing
my aspx page. This tool internally uses aspnet_regiis, and I have explained
the problem of using it in my first post.
"WoodenSWord" wrote: You can check this site out:
http://www.denisbauer.com/NETTools/A...nSwitcher.aspx
"Rak" wrote:
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
Hi Rak,
I think using external command utility to do the work is reasonable because
the ASP.NET version setting in IIS application vdir (or site) is a purely
IIS metabase setting. Also, perform such configuration will definitely
require powerful permission. And since you're going to execute the command
in ASP.NET application, I would suggest you consider using intergrated
windows authentication in IIS, and configure your ASP.NET application to
use windows authentication. And create an Admin-Page which let admin users
to visit. Thus, we can impersonate the client-user and spawn new process to
execute command under the impersonated user...
#How to implement impersonation in an ASP.NET application http://support.microsoft.com/?id=306158
#How to spawn a process that runs under the context of the impersonated
user in Microsoft ASP.NET pages http://support.microsoft.com/?id=889251
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Thanks for the response Steve. Based on the responses I received, I gather
that aspnet_regiis is the only way to change the .NET version on IIS virtual
directory. It cannot be set using System.DirectoryServices.DirectoryEntry or
something similar.
Thanks
Rakesh
Hi Rakesh,
Actually, the ASP.NET version setting is the script extension mappings in
the IIS's site or virtual directory(application). You can check them in
the IIS manager, in the "Home Directory" Tab, click the "configuration"
button.......
And the aspnet_regiis.exe tool actually programmatically change the script
mappings internally(for all the extensions need to be processed by asp.net
, such as aspx, ascx , asax ......). Generally we won't consider manually
setting script mapping one by one, however, if necessary, you can still use
some scripts or .NET/ native code to set script mapping through ADSI
interface. Here is a web article which has mentioned this:
#Switching Versions of the ASP.Net Framework http://aspalliance.com/306
Hope this also helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Steven,
Thanks for the response. The link you suggested in your response was doing
exactly what I tried as option 2. So I went back to my option 2 and
discovered a bug that was preventing the change in .Net Version. I was
deleting the character 'v' before the version number, and hence the directory
path became invalid.
So by changing the script map programatically, I can now successfully change
..NET version. And this method even works on remote IIS.
Thanks a lot for you help.
Rakesh
Just in case anyone is looking for the solution, here it is
PropertyValueCollection scriptMapVals = siteVDir.Properties["ScriptMaps"];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersion =
ConfigurationManager.AppSettings["frameworkVersion"];
Regex versionRegex = new Regex(@"(?<=\\v)\d{1}\.\d{1}\.\d{1,5}(?=\\)");
//Assuming the version will always be something like n.n.nnnnn
foreach (string scriptMapVal in scriptMapVals)
{
if (scriptMapVal.Contains("Framework"))
{
objScriptMaps.Add(versionRegex.Replace(scriptMapVa l, frameworkVersion));
}
else
{
objScriptMaps.Add(scriptMapVal);
}
}
siteVDir.Properties["ScriptMaps"].Value = objScriptMaps.ToArray();
siteVDir.CommitChanges();
Rakesh Chenchery
Symantec UK
Thanks for your followup Rakesh,
Glad to be of assistance and also thank you for the code sharing.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Rod |
last post by:
We have a .NET application which is installed on one machine (let's call it
server 2), and we point to it using IIS from another machine (our edge
server, which I'll call server 1). So, server 1...
|
by: nick |
last post by:
I have a problem and I've been using a cheezy work around and was
wondering if anyone else out there has a better solution.
The problem:
Let's say I have a web application appA. Locally, I set...
|
by: david |
last post by:
I basically use the following code to display the directory and file names in
the WWWROOT, but can not show the virtual directory.
----
Dim path As String = Server.MapPath(x)
Dim di As...
|
by: BLetts |
last post by:
I have an ASP.NET app that must allow users to upload files. The files are
stored in a virtual directory. I use Server.MapPath to map from the virtual
directory name to a physical path, then the...
|
by: Amos Soma |
last post by:
Anyone know how I can programatically detect whether a virtual directory
exists on a machine my app is running on? And how to retrieve information
about that virtual directory?
Thanks very much....
|
by: Nate |
last post by:
I am running on Window 2003. I have a website built in ASP.NET 2.0. I need to
have a Virtual Directory running an application in 1.1. I have configured
each in its own Application Pool. The 1.1...
|
by: Rak |
last post by:
Can I use aspnet_regiis to change the .NET Version of a remote IIS virtual
directory? If yes, how can I do it. If not, what options do I have to do it
programatically?
Currently I have an...
|
by: =?Utf-8?B?bWlrZXM=?= |
last post by:
I am writing a C# Windows Application that will create virtual directories on
our Win 2003 server machines. Using the System.DirectoryServices
DirectoryEntry class I have had very little trouble...
|
by: Crash |
last post by:
..NET Framework 1.x, 2.x, 3.x...
ASP.NET 5.0, 5.1, 6.0...
Windows Server 2000, XP, Server 2003...
I am using NAnt & the NAnt contrib library to automate virtual
directory maintenance tasks on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |