简体   繁体   中英

Code working in local environment, but didn't work when hosted on iis

Requiremnet--on click of a button, a site will be created on iis.I am passing a name,that will become the name of the site on iis

I created a powershell script to do this.Using process.start, i want to open a powershell.exe and want to execute my code inside it. Code...

        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        Char[] chr = Password.ToCharArray();
        System.Security.SecureString pwd = new System.Security.SecureString();

        foreach (char c in chr)
        {
            pwd.AppendChar(c);
        }

        proc.StartInfo.FileName = "powershell.exe";

        //proc.StartInfo.Arguments = powershellScriptCode;  //It contains powershell script       to        create a new website in iis
        proc.StartInfo.UserName = UserName;  //Comes from config file
        proc.StartInfo.Password = pwd;        //Comes from config file
        proc.StartInfo.Domain = Domain;      //Comes from config file
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.UseShellExecute = false;
        bool result = proc.Start();

when i run this code in local environment,it run sucessfully and creates a website, but when i run this code on IIS(After hosting), it is not able to create a site on IIS.so what type of permissions i required.

You need to change the identitiy in the Application Pool. Go to IIS Manager -> Application Pools -> Advanced Settings -> Process Model -> Identity. Change it to "Local system" and try again (but remember to change it back unless you know what you are doing, security-wise; if it works, create a user account with just the required permissions).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM