Adding ASP.NET impersonation users of specific domain to windows authentication

淺唱寂寞╮ 提交于 2019-12-13 08:01:20

问题


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:


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



来源:https://stackoverflow.com/questions/32384262/adding-asp-net-impersonation-users-of-specific-domain-to-windows-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!