开发者

Windows Authentication in silverlight Vs 2010

I want to implemen开发者_开发百科t windows Authentication in silver light, How to do that ?


There is a workaround if you are hosting your Silverlight application in an ASP.NET page.

  1. Make sure that your website (hosting the Silverlight .xap and ASPX page) has Windows Integration security enabled, and anonymous access disabled.

  2. Add the following to your list:

    <param name="initParams" value="myCustomParam1=Foo,userId=<% System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal; Response.Write(p.Identity.Name); %>" />

This will pass your username pulled from ASP.NET into your Silverlight application.

  1. Add this line to your App.xaml.cs page, in the Application_Startup method:

    // Take parameters and store them in application resources
    if (e.InitParams != null)
    {
        foreach (var data in e.InitParams)
        {
            this.Resources.Add(data.Key, data.Value);
        }
    }
    
  2. Once you have the above steps in place, you can access your value from page code behind using the following:

    App.Current.Resources["userId"].ToString();

  3. Also, as an alternative, if you run your application on an Intranet, and run it in out-of-browser mode with elevated security, this is all much easier. You can access the Windows API using this:

    if (Application.Current.HasElevatedPermissions) { using (dynamic wshNetwork = AutomationFactory.CreateObject("WScript.Network")) { return (wshNetwork.UserName); } }


As far as I know it's not possible to use Windows Authentication "directly" in Silverlight (at least with a self-hosted WCF service -maybe with IIS there is some support?).

An acceptable way to accomplish this in my opinion is to pass username/password to your server and there you query the Active Directory using an LDAP library. Make sure to use SSL for your service calls otherwise the credentials will travel in clear over the wire.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜