Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > programatically changing the .net version of virtual directory

Reply
Thread Tools

programatically changing the .net version of virtual directory

 
 
=?Utf-8?B?UmFr?=
Guest
Posts: n/a
 
      05-17-2006
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?V29vZGVuU1dvcmQ=?=
Guest
Posts: n/a
 
      05-17-2006
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

 
Reply With Quote
 
=?Utf-8?B?UmFr?=
Guest
Posts: n/a
 
      05-17-2006
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

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-18-2006
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.)

 
Reply With Quote
 
=?Utf-8?B?UmFr?=
Guest
Posts: n/a
 
      05-18-2006

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
 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-19-2006
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.)

 
Reply With Quote
 
=?Utf-8?B?UmFr?=
Guest
Posts: n/a
 
      05-19-2006

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
 
Reply With Quote
 
=?Utf-8?B?UmFr?=
Guest
Posts: n/a
 
      05-19-2006
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
 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-22-2006
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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How To Modify An IIS Virtual Directory "ASP.NET Version"Programmatically? Crash ASP .Net 0 03-19-2008 11:18 PM
Set ASPNET Version for Virtual Directory from C# App =?Utf-8?B?bWlrZXM=?= ASP .Net 1 08-06-2007 06:48 PM
Does changing .NET version on one virtual directory force IIS to restart? MarkusJNZ@gmail.com ASP .Net 3 11-20-2006 12:08 AM
Changing the password of Connect As field of a Virtual directory from c# YaronP ASP .Net 0 05-05-2005 10:32 AM
Having problems changing where the virtual directory points to Rod ASP .Net 1 09-10-2003 03:00 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57