2014-06-12 1 views

답변

2

, 다음의 모든 필요 :

<system.web> 
    <authentication mode="Windows" /> 
    <httpRuntime targetFramework="4.5" /> 
    <authorization> 
    <deny users="?"/> 
    </authorization> 
</system.web> 
    <system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 

다음,이 클래스가 필요합니다

서버 :

public class ServiceEvents : IdeaBlade.EntityModel.Server.ServiceHostEvents 
{ 
    public override void OnEndpointCreated(System.ServiceModel.Description.ServiceEndpoint endpoint) 
    { 
    base.OnEndpointCreated(endpoint); 

    if (endpoint.Binding is CustomBinding) 
    { 
     var binding = endpoint.Binding as CustomBinding; 
     var elements = binding.CreateBindingElements(); 

     var tbe = elements.Find<TransportBindingElement>(); 
     var httpbe = tbe as HttpTransportBindingElement; 
     httpbe.AuthenticationScheme = System.Net.AuthenticationSchemes.Negotiate; 
     endpoint.Binding = new CustomBinding(elements); 
    } 
} 

}

그리고 마지막으로, Visual Studio에서 :

  1. 웹 프로젝트를 선택하십시오.
  2. 속성 창을 엽니 다.

    var userName = HttpContext.Current.User.Identity.Name; 
    

    :

  3. 설정 익명 인증을 '사용 안 함'
  4. 설정 윈도우 인증은

지금 사용자 정의 IEntityLoginManager에, 당신은 도메인 사용자 이름을 사용하려면 다음 사용할 수있는 '사용'하는 그런 다음 userName을 사용하여 사용자의 역할/권한을 조회 할 수 있습니다.

그리고 마지막으로 IIS에서 Windows 인증 기능을 사용하도록 설정해야합니다. 제어판/프로그램 및 기능/Windows 기능 켜기/끄기/World Wide Web 서비스/보안/Windows 인증에서 켜거나 끕니다.

위 단계 중 하나라도 누락되면 userName은 null이됩니다.