SORU
17 EYLÜL 2008, ÇARŞAMBA


ASP.NET MVC uygulama Profil Sağlayıcısı

Beni hayat için, ben SqlProfileProvider üzerinde çalıştığım bir MVC projesinde çalışmaya başlayın.

Anladım ki ilk ilginç şey Visual Studio otomatik olarak sizin için ProfileCommon proxy sınıfı oluşturmaz. Bu simpy ProfileBase sınıfı uzanan bir konu olduğu için büyük bir anlaşma değil. ProfileCommon sınıfı oluşturduktan sonra, kullanıcı profili oluşturmak için aşağıdaki işlem yöntemi yazdım.

[AcceptVerbs("POST")]
public ActionResult CreateProfile(string company, string phone, string fax, string city, string state, string zip)
{
    MembershipUser user = Membership.GetUser();
    ProfileCommon profile = ProfileCommon.Create(user.UserName, user.IsApproved) as ProfileCommon;

    profile.Company = company;
    profile.Phone = phone;
    profile.Fax = fax;
    profile.City = city;
    profile.State = state;
    profile.Zip = zip;
    profile.Save();

    return RedirectToAction("Index", "Account"); 
}

Yaşadığım sorun ProfileCommon için arayın.() Oluşturamıyor açıkçası profilini beri başarısız bir sonraki satıra neden benim profil nesne, geri almak mümkün değilim bu yüzden ProfileCommon türü, atama null.

Aşağıdaki benim web parçacık.config:

<profile defaultProvider="AspNetSqlProfileProvider" automaticSaveEnabled="false" enabled="true">
    <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" />
    </providers>
    <properties>
        <add name="FirstName" type="string" />
        <add name="LastName" type="string" />
        <add name="Company" type="string" />
        <add name="Phone" type="string" />
        <add name="Fax" type="string" />
        <add name="City" type="string" />
        <add name="State" type="string" />
        <add name="Zip" type="string" />
        <add name="Email" type="string" >
    </properties>
</profile>
The MembershipProvider is working without a hitch, so I know that the connection string is good. Just in case it's helpful, here is my ProfileCommon class:
public class ProfileCommon : ProfileBase
    {
        public virtual string Company
        {
            get
            {
                return ((string)(this.GetPropertyValue("Company")));
            }
            set
            {
                this.SetPropertyValue("Company", value);
            }
        }

        public virtual string Phone
        {
            get
            {
                return ((string)(this.GetPropertyValue("Phone")));
            }
            set
            {
                this.SetPropertyValue("Phone", value);
            }
        }

        public virtual string Fax
        {
            get
            {
                return ((string)(this.GetPropertyValue("Fax")));
            }
            set
            {
                this.SetPropertyValue("Fax", value);
            }
        }

        public virtual string City
        {
            get
            {
                return ((string)(this.GetPropertyValue("City")));
            }
            set
            {
                this.SetPropertyValue("City", value);
            }
        }

        public virtual string State
        {
            get
            {
                return ((string)(this.GetPropertyValue("State")));
            }
            set
            {
                this.SetPropertyValue("State", value);
            }
        }

        public virtual string Zip
        {
            get
            {
                return ((string)(this.GetPropertyValue("Zip")));
            }
            set
            {
                this.SetPropertyValue("Zip", value);
            }
        }

        public virtual ProfileCommon GetProfile(string username)
        {
            return ((ProfileCommon)(ProfileBase.Create(username)));
        }
    }

Any thoughts on what I might be doing wrong? Have any of the rest of you successfully integrated a ProfileProvider with your ASP.NET MVC projects?

Thank you in advance...

&text=

Here's what you need to do:

1) In Web.config's section, add "inherits" attribute in addition to your other attribute settings:

<profile inherits="MySite.Models.ProfileCommon" defaultProvider="....

2) Remove entire <properties> section from Web.config, since you have already defined them in your custom ProfileCommon class and also instructed to inherit from your custom class in previous step

3) Change the code of your ProfileCommon.GetProfile() method to

public virtual ProfileCommon GetProfile(string username)        
{            
     return Create(username) as ProfileCommon;      
}

Hope this helps.

&

CEVAP
12 Ocak 2009, PAZARTESİ


Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • akalyne

    akalyne

    13 Mayıs 2009
  • Android Developers

    Android Deve

    9 Kasım 2007
  • Bach Vlogs

    Bach Vlogs

    18 HAZİRAN 2011