为了使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将为null。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句