mirakl
mirakl

Reputation: 167

Assign application pool to website in iis7 programmatically

I'm using the following method to create application pool and assign it to web site.

This is code for application pool creation:

WebSiteName = some website name which existed.

I see that all values are get where they should be in debug mode

 private void ConfiugreAppPoolIIS7(targetMachine)
    {
        var mgr =  ServerManager.OpenRemote(targetMachine);

        if (AppPoolProp.ContainsKey("SomeTestAppPool"))
        {
            string reqAppPool = AppPoolProp["SomeTestAppPool"];

            if (!mgr.ApplicationPools.Any(pool => pool.Name == reqAppPool))
            {
                ApplicationPool myApp = mgr.ApplicationPools.Add(reqAppPool);
                myApp.AutoStart = true;
                myApp.ManagedPipelineMode = ManagedPipelineMode.Classic;
                myApp.ManagedRuntimeVersion = "V4.0";
                myApp.ProcessModel.IdentityType = ProcessModelIdentityType.NetworkService;
                myApp.Enable32BitAppOnWin64 = true;

                mgr.CommitChanges();

                foreach (Site site in mgr.Sites)
                {
                   if(site.Name == WebSiteName)
                   {
                       site.Stop();
                       site.ApplicationDefaults.ApplicationPoolName = myApp.Name;
                       site.Start();
                       mgr.CommitChanges();
                   }

                }

            }

        }
    }

The result is, I see the Aplication pool created successfuly, and the Website created as well, but, I see in the advanced settings of my web site the default appplication pool is assigned.

Could you please help?

Upvotes: 2

Views: 2251

Answers (1)

mirakl
mirakl

Reputation: 167

The problem has been fixed by fixing reference to right Microsoft.Web.Administration.dll

Cause of this server manage connected to express iis instead of my local iis.

Upvotes: 2

Related Questions