Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:38:52+00:00 2026-06-13T17:38:52+00:00

I built a ASP.NET Webapllication that create a User in our ActiveDirectory but if

  • 0

I built a ASP.NET Webapllication that create a User in our ActiveDirectory but if I install it on the IIS7 I get a Error with not rights to add a User in Ad. Now I want create a Service that can do this but I have the same problems. The command is a Powershell command and I have install the modul for ActiveDirectory.

Here a few Informations about my Project:

My asmx code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Security;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Remoting;
using System.Security;
using System.Security.Cryptography;
using System.IO;

namespace ActiveDirectoryService
{
    /// <summary>
    /// Zusammenfassungsbeschreibung für Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // Um das Aufrufen dieses Webdiensts aus einem Skript mit ASP.NET AJAX zuzulassen, heben Sie die Auskommentierung der folgenden Zeile auf. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string Connectiontest()
        {
            return "Die Verbindung besteht";
        }

        [WebMethod]
        public string GetUsername()
        {
            return User.Identity.Name;
        }

        [WebMethod]
        public string CreateADUserInNPS(string macAdress)
        {
            string prefix = "test";
            string principlename = macAdress + "@company-test.com";
            string gn = "test";
            string sn = "test";
            string Path = "..."; //The path is correct but I don't want show this

            return AddNewUser(prefix, macAdress, principlename, gn, sn, Path);

        }

        public string AddNewUser(string prefix, string macAdress, string principlename, 
                               string gn, string sn, string path)
        {
            SecureString SECUREADADMINPASSWORD = new SecureString();

            foreach (char x in macAdress)
            {
                SECUREADADMINPASSWORD.AppendChar(x);
            }

            InitialSessionState initial = InitialSessionState.CreateDefault();
            Environment.SetEnvironmentVariable("ADPS_LoadDefaultDrive", "0");
            initial.ImportPSModule(new string[] { "ActiveDirectory" });

            using (Runspace runspace = RunspaceFactory.CreateRunspace(initial))
            {
                runspace.Open();
                using (Pipeline p = runspace.CreatePipeline())
                {
                    Command command = new Command("New-ADUser");
                    command.Parameters.Add("Name", prefix);
                    command.Parameters.Add("sAMAccountName", macAdress);
                    command.Parameters.Add("UserPrincipalName", principlename);
                    command.Parameters.Add("GivenName", gn);
                    command.Parameters.Add("SurName", sn);
                    command.Parameters.Add("displayname", macAdress);
                    command.Parameters.Add("enabled", true);
                    command.Parameters.Add("Path", path);
                    command.Parameters.Add("AllowReversiblePasswordEncryption", true);
                    command.Parameters.Add("PasswordNeverExpires", true);
                    command.Parameters.Add("AccountPassword", SECUREADADMINPASSWORD);
                    p.Commands.Add(command);

                    string pscommand = "New-ADUser " + prefix + " -SamAccountName " + macAdress +
                    " -UserPrincipalName " + macAdress + "@company-test.com -GivenName " + gn + // @company-test.com aus cfg
                    " -SurName " + sn + " -displayname " + macAdress + " -enabled $true -Path " + path +
                    " -AllowReversiblePasswordEncryption $true -PasswordNeverExpires $true -AccountPassword (ConvertTo-Securestring" +
                    " '" + macAdress + "'" + " -asplaintext -Force)";

                    try
                    {
                        p.Invoke();   //I think here comes the Error with not the rights
                        return "erfolg";
                    }
                    catch (Exception ex)
                    {
                        return "Meldung: " + ex.Message;
                    }
                }
            }
        }
    }
}

On my Client it works but not if I install it on the IIS7.

My aspx code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ActiveDirectoryCenter.serv;

namespace ActiveDirectoryCenter
{
    public partial class main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnConnectionTest_Click(object sender, EventArgs e)
        {
            serv.Service1 service = new Service1();
            service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
            lblConnection.Text = service.Connectiontest();
        }

        protected void btnGetUsername_Click(object sender, EventArgs e)
        {
            serv.Service1 service = new Service1();
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;
            lblUsername.Text = service.GetUsername();
        }

        protected void btncreateADUser_Click(object sender, EventArgs e)
        {
            serv.Service1 service = new Service1();
            service.Credentials = System.Net.CredentialCache.DefaultCredentials;
            lblstatus.Text = service.CreateADUserInNPS(txtMacAdress.Text);

        }
    }
}

Here the Idea

enter image description here

I make it first without a service but now I want a aspx site and a service that have the methods.
I configurate the service so:

enter image description here
enter image description here

I know it is a difficult question but maybe I get help 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:38:53+00:00Added an answer on June 13, 2026 at 5:38 pm

    just trying to help from my own experience.

    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
    

    comment it out, and if it fails figure out which credentials to use.

    that is in your web client.

    something else: have your own iis application pool.

    1. your own
    2. you need to find out if it should be classic .net or integrated when it comes to application pool mode. classic .net usually is for old .net web apps, like coming from asp.net 1.1 or 2.0.

    by the way, what are error number and message and description and so forth?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've built an ASP.NET application that's using Forms Authentication. In our hosting account control
I have built an ASP.NET MVC 2 website that I am hosting with Rackspace
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that
I have built an ASP.NET mvc web application and it seems that some of
I am using built-in asp.net Role and membership provider in my website. when user
is there a built-in property in any of the ASP.net classes that determines what
I've built ASP.NET Web Services in the past that either were publicly consumed, or
Scenario: I have built an ASP.NET MVC application that manages my cooking recipes. I
I've built an ASP.NET application and noticed that my /App_Data folder contains two files:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.