如何通过电子邮件获取用户 [英] how to get user by email

查看:129
本文介绍了如何通过电子邮件获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main(string[] args)
        {
            SPSite mySite = new SPSite("sitename");
            SPWeb myWeb = mySite.OpenWeb();
            SPContext currentContext = SPContext.Current;
            string userEmail = "emailaddress"; // get from txtEmail.Text control
            string userName = Membership.GetUserNameByEmail(userEmail);
            Console.WriteLine("Your UserName is: " + userName);
        }



此代码将NULL调整.我在这段代码中做错了什么.我正在尝试使用电子邮件获取用户ID.

[edit]已添加代码块-OriginalGriff [/edit]

[从OP添加]
我的意思是.用户名为空. Membership.GetUserNameByEmail返回Null值.



This code is retuning NULL. What am i doing wrong in this code. i am trying to get userID using email .

[edit]Code block added - OriginalGriff[/edit]

[Added from OP]
I meant to say. UserName is Null. Membership.GetUserNameByEmail is returning Null value.

推荐答案

app.config文件中是否设置正确?

Do you have the proper settings in the app.config file?

SPSite mySite = new SPSite("sitename");
SPWeb myWeb = mySite.OpenWeb();
SPContext currentContext = SPContext.Current;



您似乎正在尝试在未正确了解SharePoint及其使用方式的情况下使用SharePoint.

SPContext.Current在控制台应用程序上没有意义,此代码未在其下运行SharePoint上下文.您也没有正确处理SPSite对象.确实,您不需要在给定的代码中使用任何这些.周期.



You seem to be attempting to work with SharePoint without a proper understanding of it and how to work with it.

SPContext.Current has no meaning on a console application, there is no SharePoint context this code is running under. You are also not properly disposing of the SPSite object. And really, there is not need whatsoever you use any of this with the code you have given. Period.


这是.ascx文件

This is .ascx File

namespace UserByEmail
{
    public partial class UserByEmail : System.Web.UI.UserControl
    {
        string _User = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            string _Email = _txtEmail.Text;
            _User = Membership.GetUserNameByEmail(_Email);
        }
        protected void Btn_Send_Click(object sender, EventArgs e)
        {
            Response.Write("This is the User : " + _User);
        }
    }
}


这篇关于如何通过电子邮件获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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