Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 找不到ProfileCommon_Asp.net_C# 4.0 - Fatal编程技术网

Asp.net 找不到ProfileCommon

Asp.net 找不到ProfileCommon,asp.net,c#-4.0,Asp.net,C# 4.0,在我的代码中找不到错误配置文件Common。我不知道如何修正这个错误。我使用system.Web.Profile放置名称空间,但错误仍然存在。有人能帮我怎么做吗?如果你知道,请帮助我。多谢各位 public partial class UserProfile : System.Web.UI.UserControl { private string _userName = ""; public string UserName { get { return _

在我的代码中找不到错误配置文件Common。我不知道如何修正这个错误。我使用system.Web.Profile放置名称空间,但错误仍然存在。有人能帮我怎么做吗?如果你知道,请帮助我。多谢各位

public partial class UserProfile : System.Web.UI.UserControl
{
    private string _userName = "";
    public string UserName
    {
        get { return _userName; }

        set { _userName = value; }
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        this.Page.RegisterRequiresControlState(this);
    }

    protected override void LoadControlState(object savedState)
    {
        object[] ctlState = (object[])savedState;
        base.LoadControlState(ctlState[0]);
        _userName = (string)ctlState[1];
    }

    protected override object SaveControlState()
    {
        object[] ctlState = new object[2];
        ctlState[0] = base.SaveControlState();
        ctlState[1] = _userName;
        return ctlState;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            // if the UserName property contains an emtpy string, retrieve the profile
            // for the current user, otherwise for the specified user
            ProfileCommon profile = this.Profile;
            if (this.UserName.Length > 0)
                profile = this.Profile.GetProfile(this.UserName);
            txtFirstName.Text = profile.FirstName;
            txtLastName.Text = profile.LastName;
            ddlGenders.SelectedValue = profile.Gender;
            if (profile.BirthDate != DateTime.MinValue)
                txtBirthDate.Text = profile.BirthDate.ToShortDateString();
            ddlOccupations.SelectedValue = profile.Occupation;
            txtWebsite.Text = profile.Website;
            txtStreet.Text = profile.Address.Street;
            txtCity.Text = profile.Address.City;
            txtPostalCode.Text = profile.Address.PostalCode;
            txtState.Text = profile.Address.State;
            txtPhone.Text = profile.Contacts.Phone;
            txtFax.Text = profile.Contacts.Fax;
        }
    }
    public void Save()
    {
        // if the UserName property contains an emtpy string, save the current user's
        // profile, othwerwise save the profile for the specified user
        ProfileCommon profile = this.Profile;
        if (this.UserName.Length > 0)
            profile = this.Profile.GetProfile(this.UserName);
        profile.FirstName = txtFirstName.Text;
        profile.LastName = txtLastName.Text;
        profile.Gender = ddlGenders.SelectedValue;
        if (txtBirthDate.Text.Trim().Length > 0)
            profile.BirthDate = DateTime.Parse(txtBirthDate.Text);
        profile.Occupation = ddlOccupations.SelectedValue;
        profile.Website = txtWebsite.Text;
        profile.Address.Street = txtStreet.Text;
        profile.Address.City = txtCity.Text;
        profile.Address.PostalCode = txtPostalCode.Text;
        profile.Address.State = txtState.Text;
        profile.Contacts.Phone = txtPhone.Text;
        profile.Contacts.Fax = txtFax.Text;
        profile.Save();
    }

}
根据这些链接(,)

Web应用程序不支持自动生成ProfileCommon对象


然后,第一个链接给出了一个指向a的链接和关于的说明,以便解决问题

正如Mark指出的,配置文件仅适用于网站模板,我已经在博客上介绍了如何使用插件来促进Web应用程序项目中配置文件的使用:

您可以自己完成,下面是一个完整的工作实现,您可以下载:


对于所有只想动手的程序员来说,有一个非常简单的解决方法。您可以获取ProfileBase类型并将概要文件加载到其中,但会丢失强类型。如果您控制了概要文件中的数据,或者您确信概要文件中的数据属于某种类型,那么您就可以开始了

    string user = "Steve"; // The username you are trying to get the profile for.
    bool isAuthenticated = false;

        MembershipUser mu = Membership.GetUser(user);

        if (mu != null)
        {
            // User exists - Try to load profile 

            ProfileBase pb = ProfileBase.Create(user, isAuthenticated);

            if (pb != null)
            {
                // Profile loaded - Try to access profile data element.
                // ProfileBase stores data as objects in (I assume) a Dictionary 
                // so you have to cast and check that the cast succeeds.

                string myData = (string)pb["MyKey"];

                if (!string.IsNullOrWhiteSpace(myData))         
                {
                    // Woo-hoo - We're in data city, baby!
                    Console.WriteLine("Is this your card? " + myData + " - Ta Dah!");
                }
            }       
       }

我下载了Web Profile generator,但我不知道如何与我的项目链接?@Smitka您看过相应的文章了吗,它给出了如何合并它的说明。还要查看IrishCheiftain创建的文章。除此之外,如果要保存回配置文件,isAuthenticated必须为true。如果MembershipUser对象不为null,则您知道该用户已通过身份验证,可以安全地将该值设置为true。