如何使用Active Directory验证Silverlight应用程序? [英] How to authenticate Silverlight Application with Active Directory ?

查看:85
本文介绍了如何使用Active Directory验证Silverlight应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我是Silverlight的新手。我想用Silverlight应用程序的活动目录实现Windows身份验证,



我还没有找到完整的可下载示例。你能给我发链接吗,我可以在哪里下载这个例子?



你能建议我,我怎样才能实现这个功能。



先谢谢。

Hello Everyone,

I am new to Silverlight. I want to implement windows authentication with active directory for silverlight application,

I have not found complete downloadable example. Can you please send me the links, where can i download the example?.

Can you suggest me, how can i achieve this functionality.

Thanks in Advance.

推荐答案

你的问题只有一个答案...... 如何:使用Windows身份验证为Silverlight应用程序保护服务 [ ^ ]



我们无法为您完成任务,但阅读文章您将找到路径。
There is only one answer to your question... How to: Use Windows Authentication to Secure a Service for Silverlight Applications[^]

We cannot do the task for you, but reading the article you will find the path.


Hello Christian,



非常感谢你的回复。



我自己解决了这个问题。



我发布下面的代码,可能会帮助其他人:



第1步:

创建新项目并创建新的Web服务。

第2步:

写下面的方法:



Hello Christian,

Thank you very much for your reply.

I've solved the issue myself.

I am posting the code below, which may help others:

Step 1:
Create new project and Create New Webservice.
Step 2:
Write the following method:

[WebMethod(Description = "Validate a username and password against Active Directory")]
       public bool Authentication(string domain, string username, string password)
       {
           var val = true;
           try
           {
               DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, username, password);
               DirectorySearcher search = new DirectorySearcher(entry);

               search.Filter = "(SAMAccountName=" + username + ")";
               var uname = search.PropertiesToLoad.Add("cn");

               SearchResult result = search.FindOne();
               if (result == null)
               {
                   val = false;
               }
           }
           catch
           {
               val = false;
           }
           return val;
       }





第3步:

在你的项目中使用这个web服务。





Step 3:
Consume this web service in your project.

private void Register_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //User Name can not be blank
                if (txtUsername.Text.Trim() == "")
                {
                    lblStatus.Text = "Please Enter Username";
                }
                
                //Password can not be blank
                else if (txtPassword.Password == "")
                {
                    lblStatus.Text = "Please Enter Password";
                }

                else
                {
                    //Creating object for "your created web service name (I am taking my web service as Domain_Auth" web service for Authentication
// I am taking WS as proxy name here and 


                    WS.Domain_AuthSoapClient client = new WS.Domain_AuthSoapClient();
                    client.AuthenticationCompleted += new EventHandler<authenticationcompletedeventargs>(Client_AuthenticationCompleted);
                    client.AuthenticationAsync(" your domain name", txtUsername.Text, txtPassword.Password);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //Event Handler for Authentication Method
        void Client_AuthenticationCompleted(object sender, AuthenticationCompletedEventArgs e)
        {

            if (e.Error != null)
            {
                lblStatus.Text = "Sorry, an error occured. " + e.Error.Message;
            }

            if (e.Result == true)
            {
                //Do something
            }
            else
            {
                //Do something
            }
        }


</authenticationcompletedeventargs>





谢谢非常感谢。



Thank you very much.


这篇关于如何使用Active Directory验证Silverlight应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆