在asp.net中,是否仍然可以使用C#获取Hotmail电子邮件联系人而不是电子邮件哈希?

在asp.net中,是否仍然可以使用C#获取Hotmail电子邮件联系人而不是电子邮件哈希?,c#,asp.net,email,contacts,hotmail,C#,Asp.net,Email,Contacts,Hotmail,如何在asp.net中使用C#?获取Hotmail电子邮件联系人而不是电子邮件哈希,我们可以使用代理身份验证获取电子邮件。下面是我完成的代码片段 在这里输入代码 public partial class DefaultPage : System.Web.UI.Page { //Comma-delimited list of offers to be used. const string Offers = "Contacts.View"; //Name of cookie

如何在asp.net中使用C#?

获取Hotmail电子邮件联系人而不是电子邮件哈希,我们可以使用代理身份验证获取电子邮件。下面是我完成的代码片段

在这里输入代码

public partial class DefaultPage : System.Web.UI.Page
{
    //Comma-delimited list of offers to be used.
    const string Offers = "Contacts.View";
    //Name of cookie to use to cache the consent token. 
    const string AuthCookie = "delauthtoken";

    // Initialize the WindowsLiveLogin module.
    static WindowsLiveLogin wll = new WindowsLiveLogin(true);

    protected WindowsLiveLogin.ConsentToken Token;

    protected string ConsentUrl;

    protected void Page_Load(object sender, EventArgs e)
    {
        //Get the consent URL for the specified offers.
        ConsentUrl = wll.GetConsentUrl(Offers);

        HttpRequest req = HttpContext.Current.Request;
        HttpCookie authCookie = req.Cookies[AuthCookie];

        // If the raw consent token has been cached in a site cookie, attempt to
        // process it and extract the consent token.
        if (authCookie != null)
        {
            string t = authCookie.Value;
            Token = wll.ProcessConsentToken(t);
            getContacts(Token.DelegationToken,Token.LocationID);
            if ((Token != null) && !Token.IsValid())
            {
                Token = null;
            }
        }
    }

    private void getContacts(string token, string lId)
    {
        long intlid = Int64.Parse(lId, System.Globalization.NumberStyles.HexNumber);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("https://livecontacts.services.live.com/users/@C@{0}/rest/livecontacts/contacts/", intlid));
        request.UserAgent = "Windows Live Data Interactive SDK";
        request.ContentType = "application/xml; charset=utf-8";
        request.Method = "GET";
        request.Headers.Add("Authorization", "DelegatedToken dt=\"" + token + "\"");

        using (WebResponse response = request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                //docNav = new XPathDocument(stream);
                StreamReader reader = new StreamReader(stream);
              //  var contactStreamReponse = reader.ReadToEnd();

              //  XmlDocument contacts = new XmlDocument();
              //  contacts.LoadXml(contactStreamReponse);



                //Use the document. For example, display contacts.InnerXml.

              //  labelXml.Text = contacts.InnerXml;

                if (CheckBoxList1.Items.Count < 1)
                {
                    DataSet ds = new DataSet();
                    ds.ReadXml(reader);
                    response.Close();
                    if (ds.Tables["Contact"].Rows.Count > 0)
                    {
                        ArrayList al = new ArrayList();

                        for (int intC = 0; intC < ds.Tables["Email"].Rows.Count; intC++)
                        {
                            //Response.Write("FOr instance" + intC);

                            //Response.Write(ds.Tables["Email"].Rows[intC]["Address"].ToString());
                            ///Response.Write("<br>");
                            al.Add(ds.Tables["Email"].Rows[intC]["Address"].ToString());
                        }
                        CheckBoxList1.DataSource = al;
                        CheckBoxList1.DataBind();

                    }

                }
                else
                {
                    return;
                }
            }


        }
    }
public部分类DefaultPage:System.Web.UI.Page
{
//要使用的报价的逗号分隔列表。
const string Offers=“Contacts.View”;
//用于缓存同意令牌的cookie的名称。
常量字符串AuthCookie=“delauthtoken”;
//初始化WindowsLiveLogin模块。
静态WindowsLiveLogin wll=新WindowsLiveLogin(true);
受保护的WindowsLiveLogin.ApproveToken令牌;
受保护的字符串URL;
受保护的无效页面加载(对象发送方、事件参数e)
{
//获取指定优惠的同意URL。
ApproveURL=wll.getApproveURL(报价);
HttpRequest req=HttpContext.Current.Request;
HttpCookie authCookie=req.Cookies[authCookie];
//如果原始同意令牌已缓存在站点cookie中,请尝试
//处理它并提取同意令牌。
if(authCookie!=null)
{
字符串t=authCookie.Value;
Token=wll.Token(t);
getContacts(Token.DelegationToken,Token.LocationID);
如果((Token!=null)&&!Token.IsValid())
{
令牌=null;
}
}
}
私有void getContacts(字符串标记、字符串盖)
{
long intlid=Int64.Parse(lId,System.Globalization.NumberStyles.HexNumber);
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(string.Format(“https://livecontacts.services.live.com/users/@C@{0}/rest/livecontacts/contacts/”,intlid));
request.UserAgent=“Windows Live数据交互SDK”;
request.ContentType=“application/xml;charset=utf-8”;
request.Method=“GET”;
request.Headers.Add(“Authorization”,“DelegatedToken dt=\”“+令牌+”\”);
使用(WebResponse=request.GetResponse())
{
使用(Stream=response.GetResponseStream())
{
//docNav=新的XPathDocument(流);
StreamReader=新的StreamReader(流);
//var contactStreamResponse=reader.ReadToEnd();
//XmlDocument contacts=新的XmlDocument();
//contacts.LoadXml(ContactStreamResponse);
//使用文档。例如,display contacts.InnerXml。
//labelXml.Text=contacts.InnerXml;
如果(CheckBoxList1.Items.Count<1)
{
数据集ds=新数据集();
ReadXml(reader);
response.Close();
如果(ds.表格[“联系人”].行数>0)
{
ArrayList al=新的ArrayList();
对于(int intC=0;intC”);
al.Add(ds.Tables[“Email”].Rows[intC][“Address”].ToString());
}
CheckBoxList1.DataSource=al;
CheckBoxList1.DataBind();
}
}
其他的
{
返回;
}
}
}
}

大家好,欢迎来到SO!请不要只是发布一个没有真正解释的链接-提供一个摘要,文章中的一段代码,任何显示出一些努力的东西。它将帮助任何其他来寻找这个答案的人。=)