IIS "management" with c#

Creating Virtual Directories with c#

Page 1 of 1

1 Replies - 4952 Views - Last Post: 15 March 2010 - 01:00 AM Rate Topic: -----

#1 clabbeman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-December 09

IIS "management" with c#

Posted 15 March 2010 - 12:14 AM

Hey all who Dreamincode.

Been facing a few minor issues when trying to manage IIS with my Windows Application.
I can create sites without any problem but when i wanna point a Virtual Directory to a specific site it stops and sais RPC-Server is unavailable.
Been googling it and found out that its something with authentication security in windows so ive tried to reconfigure a few things to make it work better. However there is still one thing that im scratching my head about.

When i do it with code it becomes an application under the site.
If i do it in IIS - manager it doesnt. And ive tried to find some other help about it on the net but they all have app.create in the code.
Posting code under here:

IIS version: 7 with 6 compability activated.

string pref = Prefix name like abc001 (have a function to make sure that it becomes the right format with 3 alphs and 3 numbers.)
string vPhys = The physical path on the computer where the wanted virtual directory exists.

void createVD(string pref, string vPhys, int siteID)
        {
            //DirectoryEntries oDC = new DirectoryEntries();
            string IISid = siteID.ToString();
            DirectoryEntry iISAdmin = new DirectoryEntry("IIS://localhost/w3svc/" + IISid + "/Root");
            //oDC = iISAdmin.Children;

            DirectoryEntry vdir = iISAdmin.Children.Add(pref, iISAdmin.SchemaClassName.ToString());
            try
            {

                vdir.Properties["Path"][0] = vPhys;
                vdir.Properties["AppFriendlyName"][0] = pref;
                vdir.Properties["EnableDirBrowsing"][0] = false;
                vdir.Properties["AccessRead"][0] = true;
                vdir.Properties["AccessExecute"][0] = true;
                vdir.Properties["AccessWrite"][0] = false;
                vdir.Properties["AccessScript"][0] = true;
                vdir.Properties["AuthNTLM"][0] = true;
                vdir.Properties["EnableDefaultDoc"][0] = true;
                vdir.Properties["DefaultDoc"][0] = "default.htm,default.aspx,default.asp";
                vdir.Properties["AspEnableParentPaths"][0] = true;
                vdir.CommitChanges();
                //'the following are acceptable params
                //'INPROC = 0
                //'OUTPROC = 1
                //'POOLED = 2

                vdir.Invoke("AppCreate", 1);
            }
            catch
            {
                mLog = "Couldnt create Virtual Directory."; (translated from swedish)
            }
        }



So my thoughts here was.. Can i, with code, create a Virtual Directory or does it need to be an application under the site?
I havent worked much with IIS combo and c# and since i only find application creates on the net im a little confused.
Am i missing something really easy? :s

//Claus

*edit note*
Im working on the code as i wait so it will be updated. Trying to write the updates here.
Found one small issue.. Forgot to specify the site ID under new DirectoryEntry. Fixed. But still it creates an application.
oDC aint used anywhere, forgot to comment it away when posted.

This post has been edited by clabbeman: 15 March 2010 - 12:51 AM


Is This A Good Question/Topic? 0
  • +

Replies To: IIS "management" with c#

#2 clabbeman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-December 09

Re: IIS "management" with c#

Posted 15 March 2010 - 01:00 AM

Ok it was really easy..
Almost embarrased :P

try
            {

                vdir.Properties["Path"][0] = vPhys;
                vdir.Properties["AppFriendlyName"][0] = pref;
                vdir.Properties["EnableDirBrowsing"][0] = false;
                vdir.Properties["AccessRead"][0] = true;
                vdir.Properties["AccessExecute"][0] = true;
                vdir.Properties["AccessWrite"][0] = false;
                vdir.Properties["AccessScript"][0] = true;
                vdir.Properties["AuthNTLM"][0] = true;
                vdir.Properties["EnableDefaultDoc"][0] = true;
                vdir.Properties["DefaultDoc"][0] = "default.htm,default.aspx,default.asp";
                vdir.Properties["AspEnableParentPaths"][0] = true;
                vdir.CommitChanges();
                //'the following are acceptable params
                //'INPROC = 0
                //'OUTPROC = 1
                //'POOLED = 2
                
                //vdir.Invoke("AppCreate", 1);
            }



So for those who finds them selves with the same problem.. Dont use DirectoryEntry.Invoke(). It turns it into a IISapplication under the site.
Problem Solved.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1