473,598 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

programatically changing the .net version of virtual directory

Rak
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
DirectoryServic es.DirectoryEnt ry 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.e xe. I tried 2 different solutions:-
----------------------------------------------------------------------
1. Call aspnet_regiis.e xe -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.e xe

//Code in aspx page
string strFrameworkVer sion =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];
string winPath = Environment.Get EnvironmentVari able("windir");
string fullPath = winPath + @"\Microsoft.NE T\Framework\v" +
strFrameworkVer sion + @"\aspnet_regii s.exe";
string args = " -s " + "W3SVC/1/root/" + nameDirectory;

ProcessStartInf o startInfo = new ProcessStartInf o(fullPath);
startInfo.Windo wStyle = ProcessWindowSt yle.Hidden;
startInfo.UseSh ellExecute = false;
startInfo.Redir ectStandardOutp ut = true;
startInfo.Redir ectStandardErro r = true;

System.Diagnost ics.Process process = new System.Diagnost ics.Process();
startInfo.Argum ents = args;
process.StartIn fo = startInfo;
process.Start() ;
process.WaitFor Exit();

---------------------------------------------------------------
2. I tried to modify the scriptmap programatically to match what
aspnet_regiis.e xe 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.

PropertyValueCo llection vals = siteVDir.Proper ties["ScriptMaps "];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersio n =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];

foreach (string val in vals)
{
if (val.Contains(" Framework"))
{
string version = val.Substring(v al.IndexOf("Fra mework")
+ 10, 9);
if(version != frameworkVersio n)
{
objScriptMaps.A dd( val.Replace(ver sion,
frameworkVersio n));
}
}
else
{
objScriptMaps.A dd(val);
}
}

siteVDir.Proper ties["ScriptMaps "].Value =
objScriptMaps.T oArray();
siteVDir.Commit Changes();
------------------------------------------

What is the most appropriate way to change the .NET version of the created
virtual directory, programatically from within as aspx page?

Thanks
Rakesh
May 17 '06 #1
8 7762
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
DirectoryServic es.DirectoryEnt ry 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.e xe. I tried 2 different solutions:-
----------------------------------------------------------------------
1. Call aspnet_regiis.e xe -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.e xe

//Code in aspx page
string strFrameworkVer sion =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];
string winPath = Environment.Get EnvironmentVari able("windir");
string fullPath = winPath + @"\Microsoft.NE T\Framework\v" +
strFrameworkVer sion + @"\aspnet_regii s.exe";
string args = " -s " + "W3SVC/1/root/" + nameDirectory;

ProcessStartInf o startInfo = new ProcessStartInf o(fullPath);
startInfo.Windo wStyle = ProcessWindowSt yle.Hidden;
startInfo.UseSh ellExecute = false;
startInfo.Redir ectStandardOutp ut = true;
startInfo.Redir ectStandardErro r = true;

System.Diagnost ics.Process process = new System.Diagnost ics.Process();
startInfo.Argum ents = args;
process.StartIn fo = startInfo;
process.Start() ;
process.WaitFor Exit();

---------------------------------------------------------------
2. I tried to modify the scriptmap programatically to match what
aspnet_regiis.e xe 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.

PropertyValueCo llection vals = siteVDir.Proper ties["ScriptMaps "];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersio n =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];

foreach (string val in vals)
{
if (val.Contains(" Framework"))
{
string version = val.Substring(v al.IndexOf("Fra mework")
+ 10, 9);
if(version != frameworkVersio n)
{
objScriptMaps.A dd( val.Replace(ver sion,
frameworkVersio n));
}
}
else
{
objScriptMaps.A dd(val);
}
}

siteVDir.Proper ties["ScriptMaps "].Value =
objScriptMaps.T oArray();
siteVDir.Commit Changes();
------------------------------------------

What is the most appropriate way to change the .NET version of the created
virtual directory, programatically from within as aspx page?

Thanks
Rakesh

May 17 '06 #2
Rak
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.
"WoodenSWor d" 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
DirectoryServic es.DirectoryEnt ry 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.e xe. I tried 2 different solutions:-
----------------------------------------------------------------------
1. Call aspnet_regiis.e xe -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.e xe

//Code in aspx page
string strFrameworkVer sion =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];
string winPath = Environment.Get EnvironmentVari able("windir");
string fullPath = winPath + @"\Microsoft.NE T\Framework\v" +
strFrameworkVer sion + @"\aspnet_regii s.exe";
string args = " -s " + "W3SVC/1/root/" + nameDirectory;

ProcessStartInf o startInfo = new ProcessStartInf o(fullPath);
startInfo.Windo wStyle = ProcessWindowSt yle.Hidden;
startInfo.UseSh ellExecute = false;
startInfo.Redir ectStandardOutp ut = true;
startInfo.Redir ectStandardErro r = true;

System.Diagnost ics.Process process = new System.Diagnost ics.Process();
startInfo.Argum ents = args;
process.StartIn fo = startInfo;
process.Start() ;
process.WaitFor Exit();

---------------------------------------------------------------
2. I tried to modify the scriptmap programatically to match what
aspnet_regiis.e xe 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.

PropertyValueCo llection vals = siteVDir.Proper ties["ScriptMaps "];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersio n =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];

foreach (string val in vals)
{
if (val.Contains(" Framework"))
{
string version = val.Substring(v al.IndexOf("Fra mework")
+ 10, 9);
if(version != frameworkVersio n)
{
objScriptMaps.A dd( val.Replace(ver sion,
frameworkVersio n));
}
}
else
{
objScriptMaps.A dd(val);
}
}

siteVDir.Proper ties["ScriptMaps "].Value =
objScriptMaps.T oArray();
siteVDir.Commit Changes();
------------------------------------------

What is the most appropriate way to change the .NET version of the created
virtual directory, programatically from within as aspx page?

Thanks
Rakesh

May 17 '06 #3
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.)

May 18 '06 #4
Rak

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.Director yServices.Direc toryEntry or
something similar.

Thanks
Rakesh
May 18 '06 #5
Hi Rakesh,

Actually, the ASP.NET version setting is the script extension mappings in
the IIS's site or virtual directory(appli cation). You can check them in
the IIS manager, in the "Home Directory" Tab, click the "configurat ion"
button.......

And the aspnet_regiis.e xe tool actually programmaticall y 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.)

May 19 '06 #6
Rak

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
May 19 '06 #7
Rak
Just in case anyone is looking for the solution, here it is

PropertyValueCo llection scriptMapVals = siteVDir.Proper ties["ScriptMaps "];
ArrayList objScriptMaps = new ArrayList();
string frameworkVersio n =
ConfigurationMa nager.AppSettin gs["frameworkVersi on"];
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.C ontains("Framew ork"))
{
objScriptMaps.A dd(versionRegex .Replace(script MapVal, frameworkVersio n));
}
else
{
objScriptMaps.A dd(scriptMapVal );
}
}

siteVDir.Proper ties["ScriptMaps "].Value = objScriptMaps.T oArray();
siteVDir.Commit Changes();

Rakesh Chenchery
Symantec UK
May 19 '06 #8
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.)

May 22 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1267
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 has a virtual directory pointing to server 2 in server 1's IIS. Well, for various reasons I want to point to a new server, I'll call server 3, to host the .NET application. I have tried changing the Network Directory in Internet Service Manager...
8
3377
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 it up as C:\domains\appA. Locally, my IIS root points to C:\domains. I don't point it to C:\domains\appA since if I have an appB under C:\domains I wouldn't be able to get to it. So to access it via my browser I go to localhost/appA.
4
2938
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 DirectoryInfo = New DirectoryInfo(path) Listing.DataSource = di.GetFileSystemInfos() Listing.DataBind() ---- Anyone can help me about how to list the virtual directory.
2
2604
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 FileUpload control SaveAs method to upload and save the file. This all works fine when the virtual directory points to a local drive on the ASP.NET server. However, when pointing to a remote drive (which is what my client wants to do), I get...
2
2045
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. Amos.
8
2526
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 application picks up and parses the 2.0 web.config. It is complaining about the connectionstrings node. If I comment out that node the applications both run. I have tried running the 1.1 application under 2.0 but there are some controls used in...
1
3353
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 application that creates a virtual directory using the System.DirectoryServices.DirectoryEntry class, and then set the appropriate properties on it. In one of my previous posts I was told that to change the ..NET version on a virtual directory I need to...
1
1841
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 remotely creating and configuring virtual directories on our servers. My problem is that I have not found a way to remotely configure the version of ASPNET that will be used by the application running in the virtual directories I create. We have...
0
2439
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 IIS servers with side-by-side installs of ASP.NET. I can automate most IIS tasks using NAnt however - to configure the ASP.NET version for a newly created virtual directory I must manually
0
7981
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2410
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.