为了使 Windows 身份验证在 DevForce Silverlight 应用程序中正常工作,需要许多不同的元素。
它们到底是什么?(我将在这里回答我自己的问题,现在我已经开始工作了。)
为了使 Windows 身份验证在 DevForce Silverlight 应用程序中正常工作,需要许多不同的元素。
它们到底是什么?(我将在这里回答我自己的问题,现在我已经开始工作了。)
在 web.config 中,以下所有内容都是必需的:
<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 中:
现在在自定义 IEntityLoginManager 中,您可以使用以下内容获取域用户名:
var userName = HttpContext.Current.User.Identity.Name;
然后,您可以使用 userName 来查找用户的角色/权限。
最后,必须在 IIS 中启用 Windows 身份验证功能。这可以从控制面板/程序和功能/打开或关闭 Windows 功能/万维网服务/安全/Windows 身份验证打开/关闭。
如果缺少上述任何步骤,则 userName 将为空。