PDA

View Full Version : مشکل در ایجاد Profile برای کاربران



Cessna182
پنج شنبه 13 بهمن 1390, 14:25 عصر
دوستان مشکلی که از صبح تا حالا دارم باهاش سر و کله میزنم ایجاد پروفایل برای کاربران هست

توی web.config
این پارامترها رو اضافه کردم

<profile>
<properties>
<add name="CreditCard" type="System.String" />
<add name="Address1" type="System.String" />
<add name="Address2" type="System.String" />
<add name="City" type="System.String" />
<add name="Region" type="System.String" />
<add name="PostalCode" type="System.String" />
<add name="Country" type="System.String" />
<add name="ShippingRegion" type="System.String" />
<add name="DayPhone" type="System.String" />
<add name="EvePhone" type="System.String" />
<add name="MobPhone" type="System.String" />
</properties>
</profile>

بعد یک کلاسی درست کردم به نام CustomerWrapper
و بدین شکل پیش رفتم:



using System;
using System.Web;
using System.Web.Security;


public class ProfileWrapper
{
private string address1;
private string address2;
private string city;
private string region;
private string postalCode;
private string country;
private string shippingRegion;
private string dayPhone;
private string evePhone;
private string mobPhone;
private string email;
private string creditCard;
private string creditCardHolder;
private string creditCardNumber;
private string creditCardIssueDate;
private string creditCardIssueNumber;
private string creditCardExpiryDate;
private string creditCardType;
public ProfileWrapper()
{
ProfileCommon profile =
HttpContext.Current.Profile as ProfileCommon;
address1 = profile.Address1;
address2 = profile.Address2;
city = profile.City;
region = profile.Region;
postalCode = profile.PostalCode;
country = profile.Country;
.
.
.
.
{


مسئله اینجاست که ProfileCommon اصلا شناخته نمیشه! در حالیکه شی ProfileCommon هرگاه داخل webconfig قسمت پروفایلها، خصیصه های اضافه کنی اتوماتیک باید ساخته بشه!
در حالیکه اینجا ساخته نشده و اصلا نمی دونم علتش چیه؟!
دوستان لطفا راهنمایی کنید!

TeacherMath
پنج شنبه 13 بهمن 1390, 22:08 عصر
شاید دارید از web app استفاده می کنید . توی web site به صورت خودکار شناخته میشه.

Cessna182
جمعه 14 بهمن 1390, 21:48 عصر
شاید دارید از web app استفاده می کنید . توی web site به صورت خودکار شناخته میشه.
متاسفانه web app هست
من دنبال روش های ایجاد profileCommon گشتم و این مطلب رو پیدا کردم که با چند روش مختلف توضیح داده بود. من از روش سوم استفاده کردم باقی روش ها با مشکل و خطا مواجه می شدم!

http://leedumond.com/blog/getting-strongly-typed-profile-properties-from-a-class-library/

من این کلاس ها رو ایجاد کردم و همونطور که توی مقاله توضیح داده بود توی Web.config قسمت profile بهش ارث بری کلاس customprofile رو دادم و هر کاری که گفته بود انجام دادم ولی اطلاعات کاربر به روز نمیشه!!

من دارم با یک کتاب آموزشی پیش میرم و اونجا توضیح میداد که چطوری پروفایل برای کاربران ایجاد کنیم!

ولی با مشکل profileCommon مواجه شدم. همچنین objectDataSource برای نمایش و ویرایش اطلاعات کاربران استفاده می کنم که از profileDataSource استفاده می کنه. که با نگاهی به کلاس ProfileDataSourceمتوجه روش کارش می شید.

در ضمن من از جدول پیش فرض asp.net که با ایجاد یک کنترل لاگین درست میشه استفاده می کنم. و بالطبع این جدول فیلدهایی مانند شماره تلفن نداره! و متوجه نیستم به چه شکل با ساختن این properties ها، این فیلدها در جدول membership ایجاد میشه!

دوستان لطفا راهنمایی کنید

کلاس customProfile



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace onlineShop
{
public class CustomProfile:System.Web.Profile.ProfileBase
{
private string firstName="FirstName";
private string lastName="LastName";
private string nationalID="NationalID";
private string fishNumber="FishNumber";
private string credit="Credit";
private string address1="Address1";
private string address2="Address2";
private string city="City";
private string street="Street";
private string postalCode="PostalCode";
private string country="Country";
private string phone="Phone";
private string email="Email";

public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}

public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}

public string NationalID
{
get
{
return nationalID;
}
set
{
nationalID = value;
}
}

public string FishNumber
{
get
{
return fishNumber;
}
set
{
fishNumber = value;
}
}

public string Credit
{
get
{
return credit;
}
set
{
credit = value;
}
}

public string Address1
{
get
{
return address1;
}
set
{
address1 = value;
}
}

public string Address2
{
get
{
return address2;
}
set
{
address2 = value;
}
}

public string City
{
get
{
return city;
}
set
{
city = value;
}
}

public string Street
{
get
{
return street;
}
set
{
street = value;
}
}

public string PostalCode
{
get
{
return postalCode;
}
set
{
postalCode = value;
}
}

public string Country
{
get
{
return country;
}
set
{
country = value;
}
}

public string Phone
{
get
{
return phone;
}
set
{
phone = value;
}
}

public string Email
{
get
{
return email;
}
set
{
email = value;
}
}
}
}


کلاس profileInfo



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using System.Web.Security;

namespace onlineShop
{
public class ProfileInfo
{
/*private static CustomProfile Profile
{

get { return (CustomProfile)HttpContext.Current.Profile; }

}

public static string GetFullName()
{

return Profile.FirstName + " " + Profile.LastName;

}*/

private string firstName;
private string lastName;
private string nationalID;
private string fishNumber;
private string credit;
private string address1;
private string address2;
private string city;
private string street;
private string postalCode;
private string country;
private string phone;
private string email;

public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}

public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}

public string NationalID
{
get
{
return nationalID;
}
set
{
nationalID = value;
}
}

public string FishNumber
{
get
{
return fishNumber;
}
set
{
fishNumber = value;
}
}

public string Credit
{
get
{
return credit;
}
set
{
credit = value;
}
}

public string Address1
{
get
{
return address1;
}
set
{
address1 = value;
}
}

public string Address2
{
get
{
return address2;
}
set
{
address2 = value;
}
}

public string City
{
get
{
return city;
}
set
{
city = value;
}
}

public string Street
{
get
{
return street;
}
set
{
street = value;
}
}

public string PostalCode
{
get
{
return postalCode;
}
set
{
postalCode = value;
}
}

public string Country
{
get
{
return country;
}
set
{
country = value;
}
}

public string Phone
{
get
{
return phone;
}
set
{
phone = value;
}
}

public string Email
{
get
{
return email;
}
set
{
email = value;
}
}

public ProfileInfo()
{

CustomProfile profile = HttpContext.Current.Profile as CustomProfile;

firstName = profile.FirstName;
lastName = profile.LastName;
nationalID = profile.NationalID;
fishNumber = profile.FishNumber;
credit = profile.Credit;
address1 = profile.Address1;
address2 = profile.Address2;
country = profile.Country;
city = profile.City;
street = profile.Street;
postalCode = profile.PostalCode;
phone = profile.Phone;
email = Membership.GetUser(profile.UserName).Email;

}

public void UpdateProfile()
{
CustomProfile profile = HttpContext.Current.Profile as CustomProfile;

profile.FirstName = firstName;
profile.LastName = lastName;
profile.NationalID = nationalID;
profile.FishNumber = fishNumber;
profile.Credit = credit;
profile.Address1 = address1;
profile.Address2 = address2;
profile.Country = country;
profile.City = city;
profile.Street = street;
profile.PostalCode = postalCode;
profile.Phone = phone;
profile.Email = email;
}

}
}


کلاس profileDataSource



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace onlineShop
{
public class ProfileDataSource
{
public ProfileDataSource()
{
}

public List<ProfileInfo> GetData()
{
List<ProfileInfo> data = new List<ProfileInfo>();
data.Add(new ProfileInfo());
return data;
}

public void UpdateData(ProfileInfo newData)
{
newData.UpdateProfile();
}
}
}

ramin149
شنبه 15 بهمن 1390, 15:03 عصر
چرا این همه لقمه رو پیچوندید . من قبلا با پروفیل کار کردم و مشکلاتی داشتم که در سایت مطرح کردم و جواب گرفتم . یک نگاه به لینک زیر کنید . فکر کنم مشکلتون حل بشه . برای موقع آپلود با سایت .
http://barnamenevis.org/showthread.php?304176-%D9%85%D8%B4%DA%A9%D9%84-%D8%A8%D8%A7-Profile-%D8%AF%D8%B1-%D8%B3%D8%A7%DB%8C%D8%AA-%D8%A2%D9%BE%D9%84%D9%88%D8%AF-%D8%B4%D8%AF%D9%87

ramin149
شنبه 15 بهمن 1390, 15:06 عصر
در قسمت webconfig
<connectionStrings>
<add name="FlamingoASPDBConnectionString" connectionString="Data Source=ipaddress;Initial Catalog=databasename;User ID=UserName;Password=Password"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<profile defaultProvider="customizedprofileprovider" enabled="true">
<providers>
<clear/>
<add name="customizedprofileprovider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="FlamingoASPDBConnectionString" applicationName="/" description=""/>
</providers>
<properties>
<add name="FirstName" type="System.String"/>
<add name="LastName" type="System.String"/>
<add name="Email" type="System.String"/>
<add name="State" type="System.String"/>
<add name="Cite" type="System.String"/>
<add name="Address" type="System.String"/>
<add name="TellNumber" type="System.String"/>
<add name="Password" type="System.String"/>
</properties>
</profile>
</profile>

موقع نوشتن و خواندن اطلاعات در پروفایل

Pnl_Summery.Visible = true;
ProfileCommon pro = Profile.GetProfile(Session["id"].ToString());
pro.FirstName = txt_Name.Text; pro.LastName = txt_Family.Text; pro.State = cmb_state.SelectedValue; pro.Cite = txt_cite.Text; pro.Address = txt_Address.Text; pro.TellNumber = to.stringPhoneToIntPhone(txt_Tell.Text).ToString() ;
pro.Save();
lbl_Name.Text = pro.FirstName;
lbl_Family.Text = pro.LastName;
lbl_address.Text = pro.Address;
lbl_Email.Text = pro.Email;
lbl_cite.Text = pro.Cite;
lbl_State.Text = pro.State;
lbl_tell.Text = pro.TellNumber;

Cessna182
سه شنبه 18 بهمن 1390, 14:49 عصر
ممنون از راهنمایی
مسئله اینجاست که web application کلاس profilecommon رو در زمان اجرا تولید نمی کنه و باید خودت به صورت دستی درست کنی! در حالیکه website اتوماتیک profilecommon رو ایجاد می کنه و به راحتی می تونی ازش استفاده کنی!
در نهایت کار من خیلی روش های گفته شده رو انجام دادم و به نتیجه خاصی نرسیدم!
تصمیم گرفتم که یک جدول مخصوص مشخصات کاربران درست کنم و اطلاعات رو خودم داخلش بریزم و کاری به جدول membership نداشته باشم.

دوستان من دنبال کدی می گردم که هرگاه کاربری ثبت نام کرد همون موقع id کاربر ایجاد شده که یک GUID می باشد بریزه داخل جدول CUSTOMERS.

من با استفاده از این کد Guid customerid = Guid.Parse( Membership.GetUser(HttpContext.Current.User.Identi ty.Name).ProviderUserKey.ToString());

id کاربر لاگین شده رو بدست میارم ولی مسئله اینجاست وقتی که کاربر ثبت نام می کنه و گزینه sign up رو زد هنوز لاگین نشده. چون می خواستم کد بالا رو زیر این دکمه بنویسم و بتونم idش رو به جدول customers اضافه کنم.
دوستان روش دیگه ای سراغ دارید که بتونم id کاربر هنگام ثبت نام بدست بیارم؟