Re: Creating Virtual Directory
From: Scott Allen (scott_at_nospam.odetocode.com)
Date: 02/10/05
- Next message: Kevin Spencer: "Re: How to include a file in ASP.NET"
- Previous message: falcon: "RE: Long-running task: Show DIV with 'Please wait' message"
- In reply to: Jaydeep: "Re: Creating Virtual Directory"
- Next in thread: Jaydeep: "Re: Creating Virtual Directory"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Feb 2005 14:20:45 -0500
Assuming you are using a default configuration and not impersonating,
your ASP.NET code is trying to modify the IIS metabase as the ASPNET
user (Win2k, XP) or the NETWORK SERVICE user (Win2k3). These are the
accounts used to execute ASP.NET code by default, and the accounts
have limited permissions. When run as a win forms app it works because
Windows sees your identity as the one trying to modify the metabase.
Only users in the Operators and Administrators group can modify the
IIS metabase. I don't recommend putting the asp.net account into
either of these groups. Instead, for the page that needs to execute
this code, use impersonation, i.e.:
<authentication mode="Windows" />
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
<identity impersonate="true" />
Hope that gives you some information to go on,
-- Scott http://www.OdeToCode.com/blogs/scott/ On Thu, 10 Feb 2005 15:19:46 +0530, "Jaydeep" <jaydeep.vaze@solversa.com> wrote: >Hi Lionel, > Thanks for your prompt replies. sorry I forgot to add reference to >System.DirectoryService, my mistake. >I am getting "Access denied" error, when I tried to execute this code. > >private void button1_Click(object sender, System.EventArgs e) >{ >strSchema = "IIsWebVirtualDir"; >strRootSubPath = "/W3SVC/1/Root"; >DirectoryEntry deRoot= new DirectoryEntry("IIS://localhost" + >strRootSubPath); > try > { > DirectoryEntry deNewVDir = >deRoot.Children.Add("TestVirDir",strSchema); // I am getting error on this >line. > deNewVDir.Properties["Path"].Insert(0,"c:\\TestVirDir"); // Just for >example. > deNewVDir.CommitChanges(); > deRoot.CommitChanges(); > > // Create a Application > if (strSchema == "IIsWebVirtualDir") > deNewVDir.Invoke("AppCreate",true); > > // Save Changes > deNewVDir.CommitChanges(); > deRoot.CommitChanges(); > deNewVDir.Close(); > deRoot.Close(); > Response.Write("Virtual Directory TestVirDir has been created"); > } > catch (Exception ex) > { > Response.Write("Error: " + ex.Message); > } >} > >Interestingly Same code logic works when I create windows application. It >seems it is not allowing me to create Virtual Dir through web-based >application(ASP.NET & C#) because IIS is in use and this is why access is >denied error comes. So what could be the solution for this ? > >TIA >Jaydeep > > >"Lionel LASKE" <llaske@c2s.fr> wrote in message >news:%23CbvJCvDFHA.1012@TK2MSFTNGP14.phx.gbl... >> >> "Jaydeep" <jaydeep.vaze@solversa.com> a écrit dans le message de news: >> %230L7LHrDFHA.512@TK2MSFTNGP15.phx.gbl... >> > Hi Lionel, >> > I just saw the link. By reading the given web page what I realised >that >> > 1) it will not work on Win2K prof / Server machine. >> > "This example requires Windows XP Professional Service Pack 2 or Windows >> > Server 2003 Service Pack 1." >> This requirement is just for "enumerate properties". If you already know >> wich properties you need, you don't have to enumerate properties. >> >> > 2) Also I tried import System.DirectoryServices namespace in the >> > code-behind >> > of my ASPX page, but enable to do so,there is no such namespace found, >> > dont >> > know the exact reason. But I guess it is related to ADSI, Active >Directory >> > Service >> Just in case: Are you sure you add to your project a reference to >> "System.DirectoryServices.dll" ? >> >> >> > 3) The code given in the link is also incomplete >> > These are my initial observations. Still searching good link/example >> > TIA >> > Jaydeep >> > >> > "Lionel LASKE" <llaske@c2s.fr> wrote in message >> > news:OsKfFlqDFHA.3492@TK2MSFTNGP12.phx.gbl... >> >> >> >> You can use IIS SDK with System.DirectoryServices >> >> classes to make some administrative stuff on IIS. See >> >> >> > >http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/ccfc5710-93ae-474e-be09-6c7250629909.asp >> >> for more. >> >> >> >> Lionel. >> >> >> >> >> >> "Jaydeep" <jaydeep.vaze@solversa.com> a écrit dans le message de news: >> >> uNVslZqDFHA.2288@TK2MSFTNGP14.phx.gbl... >> >> > Hi, >> >> > Anybody knows how to create virtual directory programmatically under >> > root >> >> > directory ofcourse from code-behind. >> >> > I am developing web-based application where I need to create a folder >> > and >> >> > making this folder as virtual directory in IIS. >> >> > >> >> > I know in ASP how to do it. >> >> > Set objIIS = GetObject("IIS://localhost/W3SVC/1/Root") >> >> > objIIS.Create("IISWebVirtualDir", strVirtualDirectoryName) >> >> > >> >> > but how to do this in ASP.NET using C# ? >> >> > What is the namespace I should include so that I will get object of >> >> > Root >> >> > directory of IIS and then I can create virtual directory ? >> >> > >> >> > TIA >> >> > Jaydeep >> >> > >> >> > >> >> >> >> >> > >> > >> >> >
- Next message: Kevin Spencer: "Re: How to include a file in ASP.NET"
- Previous message: falcon: "RE: Long-running task: Show DIV with 'Please wait' message"
- In reply to: Jaydeep: "Re: Creating Virtual Directory"
- Next in thread: Jaydeep: "Re: Creating Virtual Directory"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|