Adding ASP.NET impersonation users of specific dom

2019-08-22 05:11发布

I have MVC4 application installed in windows server 2008 in my company(IIS 7.5). to access the windows server remotely we use(xxxxDMZ\username, password) which are the same windows authentication required to access specific page of the website. My problem is not everyone has this "xxxxDMZ" account so they can't access that page, what I am trying to do is adding their windows login credentials to access that page(by only adding the username) which that would be 'xxxx\username'.

I read that in order to do that I have to use impersonation but I can't find clear way to implement it.

Any help is haghly appreciated.

Thank you very much in advance!

1条回答
Ridiculous、
2楼-- · 2019-08-22 06:13

Here is a function you could use. But the Domain needs to be accessible from the DMZ... which means opening up ports between your DMZ and your domain controller.

public bool ValidateUser(string userName, string password)
        {
            bool validation;
            try
            {
                LdapConnection ldc = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));
                NetworkCredential nc = new NetworkCredential(userName, password, "DOMAIN NAME HERE");
                ldc.Credential = nc;
                ldc.AuthType = AuthType.Negotiate;
                ldc.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
                validation = true;
            }
            catch (LdapException)
            {
                validation = false;
            }
            return validation;
        }

ref : LDAP Authentication in ASP.Net MVC

查看更多
登录 后发表回答