2013-08-27 47 views
5

我試圖將現有的website轉換爲Web應用程序項目,並且在使配置文件工作時遇到很大問題。將網站與配置文件轉換爲網絡應用程序項目

在網站項目的代碼隱藏的一個例子是

寄存器與-角色和profile.ascx.cs

// Add the newly created user to the default Role. 
    Roles.AddUserToRole(CreateUserWizard1.UserName, wsatDefaultRole); 

    // Create an empty Profile for the newly created user 
    ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); 

    // Populate some Profile properties. Values are located in web.config file 
    p.Company.Company = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeName")).Text; 
    p.Company.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeAddress")).Text; 
    p.Company.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeCity")).Text; 
    p.Company.State = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlStates")).SelectedValue; 
    p.Company.PostalCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).Text; 
    p.Company.Phone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactPhone")).Text; 
    p.Company.Fax = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactFax")).Text; 
    p.Preferences.Newsletter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlNewsletter")).SelectedValue; 

    // Save profile - must be done since we explicitly created it 
    p.Save(); 

的web.config

<profile defaultProvider="MyCMSTableProfileProvider" automaticSaveEnabled="false" enabled="true"> 
    <providers> 
     <clear/> 
     <add name="MyCMSTableProfileProvider" applicationName="MyCMS" connectionStringName="dbMyCMSConnectionString" table="aspnet_CustomProfile" type="CustomProfile.SqlTableProfileProvider"/> 
     <add name="MyCMSStoredProcedureProfileProvider" applicationName="MyCMS" connectionStringName="dbMyCMSConnectionString" type="CustomProfile.SqlStoredProcedureProfileProvider" setProcedure="sp_wsat_SetCustomProfileData" readProcedure="sp_wsat_GetCustomProfileData"/> 
    </providers> 
    <properties> 
     <group name="Personal"> 
      <add name="FirstName" type="String" defaultValue="[null]" customProviderData="FirstName;nvarchar"/> 
      <add name="LastName" type="String" defaultValue="[null]" customProviderData="LastName;nvarchar"/> 
      <add name="Gender" type="String" defaultValue="[null]" customProviderData="Gender;nvarchar"/> 
      <add name="BirthDate" type="DateTime" defaultValue="[null]" customProviderData="BirthDate;datetime"/> 
      <add name="Occupation" type="String" defaultValue="[null]" customProviderData="Occupation;nvarchar"/> 
      <add name="Website" type="String" defaultValue="[null]" customProviderData="PersonalWebsite;nvarchar"/> 
     </group> 
     <group name="Address"> 
      <add name="Country" type="String" defaultValue="[null]" customProviderData="Country;nvarchar"/> 
      <add name="Address" type="String" defaultValue="[null]" customProviderData="Address;nvarchar"/> 
      <add name="AptNumber" type="String" defaultValue="[null]" customProviderData="AptNumber;nvarchar"/> 
      <add name="City" type="String" defaultValue="[null]" customProviderData="City;nvarchar"/> 
      <add name="State" type="String" defaultValue="[null]" customProviderData="State;nvarchar"/> 
      <add name="PostalCode" type="String" defaultValue="[null]" customProviderData="PostalCode;nvarchar"/> 
     </group> 
     <group name="Contacts"> 
      <add name="DayPhone" type="String" defaultValue="[null]" customProviderData="DayPhone;nvarchar"/> 
      <add name="DayPhoneExt" type="String" defaultValue="[null]" customProviderData="DayPhoneExt;nvarchar"/> 
      <add name="EveningPhone" type="String" defaultValue="[null]" customProviderData="EveningPhone;nvarchar"/> 
      <add name="EveningPhoneExt" type="String" defaultValue="[null]" customProviderData="EveningPhoneExt;nvarchar"/> 
      <add name="CellPhone" type="String" defaultValue="[null]" customProviderData="CellPhone;nvarchar"/> 
      <add name="Fax" type="String" defaultValue="[null]" customProviderData="Fax;nvarchar"/> 
     </group> 
     <group name="Company"> 
      <add name="Company" type="String" defaultValue="[null]" customProviderData="Company;nvarchar"/> 
      <add name="Address" type="String" defaultValue="[null]" customProviderData="Address2;nvarchar"/> 
      <add name="City" type="String" defaultValue="[null]" customProviderData="City2;nvarchar"/> 
      <add name="State" type="String" defaultValue="[null]" customProviderData="State2;nvarchar"/> 
      <add name="PostalCode" type="String" defaultValue="[null]" customProviderData="PostalCode2;nvarchar"/> 
      <add name="Phone" type="String" defaultValue="[null]" customProviderData="Phone2;nvarchar"/> 
      <add name="Fax" type="String" defaultValue="[null]" customProviderData="Fax2;nvarchar"/> 
      <add name="Website" type="String" defaultValue="[null]" customProviderData="Website2;nvarchar"/> 
     </group> 
     <group name="Preferences"> 
      <add name="Culture" type="String" defaultValue="en-US" customProviderData="Culture;nvarchar"/> 
      <add name="Newsletter" type="String" defaultValue="[null]" customProviderData="Newsletter;nvarchar"/> 
     </group> 
    </properties> 
</profile> 

但是這給出錯誤The type or namespace name 'ProfileCommon' could not be found (are you missing a using directive or an assembly reference?)

使用此example我創建了2個新的類別

ProfileInfo.cs

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

namespace myWSAT.controls 
{ 
    [Serializable] 
    public class Personal 
    { 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 
     public string Gender { get; set; } 
     public DateTime BirthDate { get; set; } 
     public string Occupation { get; set; } 
     public string Website { get; set; } 
    } 

    [Serializable] 
    public class Address 
    { 
     public string Country { get; set; } 
     public string Address1 { get; set; } 
     public string AptNumber { get; set; } 
     public string City { get; set; } 
     public string State { get; set; } 
     public string PostalCode { get; set; } 
    } 

    [Serializable] 
    public class Contacts 
    { 
     public string DayPhone { get; set; } 
     public string DayPhoneExt { get; set; } 
     public string EveningPhone { get; set; } 
     public string EveningPhoneExt { get; set; } 
     public string CellPhone { get; set; } 
     public string Fax { get; set; } 

    } 

    [Serializable] 
    public class Company 
    { 
     public string CompanyName { get; set; } 
     public string Address { get; set; } 
     public string City { get; set; } 
     public string State { get; set; } 
     public string PostalCode { get; set; } 
     public string Phone { get; set; } 
     public string Fax { get; set; } 
     public string Website { get; set; } 

    } 

    [Serializable] 
    public class Preferences 
    { 
     public string Culture { get; set; } 
     public string Newsletter { get; set; } 

    } 

    [Serializable] 
    public class ProfileInfo 
    { 
     public Personal Personal { get; set; } 
     public Address Address { get; set; } 
     public Contacts Contacts { get; set; } 
     public Company Company { get; set; } 
     public Preferences Preferences { get; set; } 
    } 

} 

wProfile.cs

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

namespace myWSAT.controls 
{ 
    public class wProfile : ProfileBase 
    { 
     public ProfileInfo ProfileInfo 
     { 
      get { return (ProfileInfo)GetPropertyValue("ProfileInfo"); } 
     } 

     public static wProfile GetProfile() 
     { 
      return (wProfile)HttpContext.Current.Profile; 
     } 

     public static wProfile GetProfile(string userName) 
     { 
      return (wProfile)Create(userName); 
     } 
    } 
} 

,然後修改 寄存器與-角色的and-profile.ascx.cs

// add newly created user to default Role specified above 
if (Roles.RoleExists(wsatDefaultRole)) 
{ 
    // Add the newly created user to the default Role. 
    Roles.AddUserToRole(CreateUserWizard1.UserName, wsatDefaultRole); 

    // Create an empty Profile for the newly created user 
    wProfile p = wProfile.GetProfile(Membership.GetUser().UserName); 
    //ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); 

    // Populate some Profile properties. Values are located in web.config file 
    p.ProfileInfo.Company.CompanyName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeName")).Text; 
    p.ProfileInfo.Company.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeAddress")).Text; 
    p.ProfileInfo.Company.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeCity")).Text; 
    p.ProfileInfo.Company.State = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlStates")).SelectedValue; 
    p.ProfileInfo.Company.PostalCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).Text; 
    p.ProfileInfo.Company.Phone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactPhone")).Text; 
    p.ProfileInfo.Company.Fax = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactFax")).Text; 
    p.ProfileInfo.Preferences.Newsletter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlNewsletter")).SelectedValue; 

    // Save profile - must be done since we explicitly created it 
    p.Save(); 

} 

這個構建和運行沒問題,但下面的行總是返回null。

wProfile p = wProfile.GetProfile(Membership.GetUser().UserName); 

我不知道什麼是錯?我也試過的例子在這個link的底部,但沒有成功

編輯:

我讀過很多鏈接,並嘗試了幾種解決方案,但我的專業就是這個面積都不是很大。我想我正在尋求一些幫助,讓它能夠運行,我會盡可能提供獎勵。

編輯: 如果我將我的嘗試將其轉換爲WAP的當前狀態可能會有所幫助。 http://www.mediafire.com/?ouabeoxwu75b52c

+0

您是否檢查瞭解決方案窗格中的參考文件夾以查看是否有任何警告?也許喲需要從源項目(可能在bin文件夾中)獲得一些DLL來修復參考 – Gonzix

+0

所有引用都可以,Web Application Projects不包含ProfileCommon類,因此我需要創建一個自定義ProfileCommon類的原因。 – user3357963

+0

也許這就是你需要的? http://stackoverflow.com/questions/1584507/web-application-project-how-to-use-profilecommon – Gonzix

回答

2

我通過你的解決方案去和所有的意見。對我來說,儘管有一件小事,但一切都很美好我注意到web.config中的配置文件元素沒有使用inherits屬性(http://msdn.microsoft.com/en-us/library/ms164644(v=vs.85).aspx)。嘗試添加這樣的屬性與價值,這是從ProfileBase抽象類派生的自定義類型的類型引用 - 在特定的例子wProfile,如下圖所示:

<profile defaultProvider="MyCMSTableProfileProvider" 
     automaticSaveEnabled="false" 
     enabled="true" 
     inherits="myWSAT.controls.wProfile"> 

做相應的修改自定義的供應商如果在這個改變之後某些東西會被打破。更重要的是,我發現類似的主題,你可能感興趣的:How to assign Profile values?

+0

@ooo:我很高興它的幫助,也感謝賞金! – jwaliszko

+0

沒問題,我被困在裏面好幾天了,這是你的建議,我失蹤了。我寧願給500英鎊500分:)。我現在已經轉換了示例網站,因此它全部作爲WAP運行。我會在明天發佈所有步驟,幫助其他人。 – user3357963

3

Membership.GetUser()返回NULL,這可以由以下原因造成:

  1. 您還沒有驗證,Membership.GetUser()將只用於身份驗證的用戶使用。否則,它將返回null。要驗證您正在處理頁面上已通過驗證的請求調用User.Identity.IsAuthenticated。如果您已獲得經過身份驗證的請求,但Membership.GetUser()仍然返回空值,則表示在成員資格數據源中找不到與經過身份驗證的用戶關聯的用戶名。使用「User.Identity.Name」驗證已驗證用戶的用戶名。

  2. 如果你打電話Membership.GetUser()重載之一,它接受用戶名,它返回null,那麼該用戶不存在於成員數據源(或我們有一個錯誤)。輕鬆驗證此方法的一種方法是使用相同的用戶名嘗試Membership.CreateUser()。如果這不會因爲重複的用戶而引發錯誤,那麼您知道用戶永遠不會存在。

  3. Membership.GetUser()應該從來沒有爲匿名用戶工作過。成員資格中沒有支持處理這種情況。

來源:MSDN Forum

但是,如果Membership.GetUser()返回null我改變對子級這一行:

wProfile p = wProfile.GetProfile(Membership.GetUser().UserName); 

if (Membership.GetUser() != null) 
{ 
    wProfile p = wProfile.GetProfile(Membership.GetUser().UserName); 
} else { 
    // do whatever you want to do when the user is null, maybe some error or create the user 
} 
+0

Membership.GetUser()方法不返回null。這部分工作正常。 – user3357963

+0

如果wProfile p = wProfile.GetProfile(Membership.GetUser()。UserName);給出一個空指針異常。只有Memberschip.GetUser()可以爲null。或者你應該有一個GetProfile的堆棧跟蹤。添加一些日誌記錄來檢查它自己。 – Peter

+0

我很抱歉,但我很積極,它與'Membership.GetUser()'沒有任何關係。我應該說這個方法總是返回null,而不是給出錯誤null異常。此外,會員詳細信息僅在用戶創建並登錄後纔可用,因此Membership.GetUser()始終返回正確登錄的用戶。 – user3357963

3

的一個問題是,你是調用Membership.GetUser()重載,它將加載當前的用戶詳細信息登錄用戶。由於這似乎是用戶可以註冊他/她自己的頁面的一部分,這意味着代碼運行時當前沒有登錄的用戶。

你或許應該改變行:這是假設你已經創造了在這一點上,用戶

wProfile p = wProfile.GetProfile(Membership.GetUser(CreateUserWizard1.UserName).UserName); 

。或者更簡單:

wProfile p = wProfile.GetProfile(CreateUserWizard1.UserName); 

不過,我會建議你也改變wProfile類以便GetProfile(string userName)將加載並返回輪廓與用戶名userName用戶。然後添加一個明確的CreateProfile(string userName)方法,您可以在創建配置文件時使用該方法。創建一個新配置文件作爲GetProfile方法的副作用在我看來並不是一個好主意。

代碼便可設爲:

wProfile p = wProfile.CreateProfile(CreateUserWizard1.UserName); 
0

的完整性和是否有人跑入一個類似的困難,下面是我走上例如網站轉換爲Web應用程序項目

的具體步驟

1)使用此walkthrough進行主轉換。這裏的要點是僅將.dll複製到新的項目bin文件夾中,然後先複製App_Code文件夾並轉換爲Web應用程序,然後再添加其他頁面和文件夾。

2)將項目轉換爲Web應用程序時,可能某些名稱空間,類和類型名稱可能無法正確更新或根據項目名稱而不同。通常背後的代碼會正確更新,但Web.Config TypeNames不會。我遇到的主要的是,其中有大約20個typenames改變theme classessp_cpanelTableAdapters,例如改變

class admin_themes_default_defaultclass admin_themes_dark_default

TypeName="sp_cpanelTableAdapters.admin_HintsTableAdapter"TypeName="myWSAT_WAP.xsd.sp_cpanelTableAdapters.admin_HintsTableAdapter"

3)下面的代碼來獲得在此Web應用程序中工作的配置我只在用戶控件membership-info.ascx中顯示了profileCommon的替代代碼 - 其他用戶控件中的代碼幾乎相同,所以我不再重複。 基於Jaroslaw Waliszko的回答,請注意Web.Config現在包含inherits="myWSAT_WAP.controls.wProfile",現在使用標準配置文件提供程序而不是自定義提供程序。

//ProfileInfo.cs 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

Namespace myWSAT_WAP.Controls 
{ 
    [Serializable] 
    public class Personal 
    { 
     public string FirstName { get; set; } 
     public string LastName { get; set; } 
     public string Gender { get; set; } 
     public DateTime BirthDate { get; set; } 
     public string Occupation { get; set; } 
     public string Website { get; set; } 
    } 

    [Serializable] 
    public class Address 
    { 
     public string Country { get; set; } 
     public string Address1 { get; set; } 
     public string AptNumber { get; set; } 
     public string City { get; set; } 
     public string State { get; set; } 
     public string PostalCode { get; set; } 
    } 

    [Serializable] 
    public class Contacts 
    { 
     public string DayPhone { get; set; } 
     public string DayPhoneExt { get; set; } 
     public string EveningPhone { get; set; } 
     public string EveningPhoneExt { get; set; } 
     public string CellPhone { get; set; } 
     public string Fax { get; set; } 

    } 

    [Serializable] 
    public class Company 
    { 
     public string CompanyName { get; set; } 
     public string Address { get; set; } 
     public string City { get; set; } 
     public string State { get; set; } 
     public string PostalCode { get; set; } 
     public string Phone { get; set; } 
     public string Fax { get; set; } 
     public string Website { get; set; } 

    } 

    [Serializable] 
    public class Preferences 
    { 
     public string Culture { get; set; } 
     public string Newsletter { get; set; } 

    } 

    [Serializable] 
    public class ProfileInfo 
    { 
     public Personal Personal { get; set; } 
     public Address Address { get; set; } 
     public Contacts Contacts { get; set; } 
     public Company Company { get; set; } 
     public Preferences Preferences { get; set; } 
    } 
} 


//wProfile.cs 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web; 
using System.Web.Profile; 

Namespace myWSAT_WAP.Controls 
{ 
    public class wProfile : ProfileBase 
    { 
     public ProfileInfo ProfileInfo 
     { 
      get { return (ProfileInfo)GetPropertyValue("ProfileInfo"); } 
     } 

     public static wProfile GetProfile() 
     { 
      return (wProfile)HttpContext.Current.Profile; 
     } 

     public static wProfile GetProfile(string userName) 
     { 
      return (wProfile)Create(userName); 
     } 
    } 
} 

//Web.config 
    <profile defaultProvider="MyCMSSqlProfileProvider" automaticSaveEnabled="false" inherits="myWSAT_WAP.controls.wProfile"> 
     <providers> 
     <clear/> 
     <add name="MyCMSSqlProfileProvider" connectionStringName="dbMyCMSConnectionString" applicationName="MyCMS" type="System.Web.Profile.SqlProfileProvider"/> 
     </providers> 
     <properties> 
     <group name="Personal"> 
      <add name="FirstName" type="String"/> 
      <add name="LastName" type="String"/> 
      <add name="Gender" type="String"/> 
      <add name="BirthDate" type="DateTime"/> 
      <add name="Occupation" type="String"/> 
      <add name="Website" type="String"/> 
     </group> 
     <group name="Address"> 
      <add name="Country" type="String"/> 
      <add name="Address" type="String"/> 
      <add name="AptNumber" type="String"/> 
      <add name="City" type="String"/> 
      <add name="State" type="String"/> 
      <add name="PostalCode" type="String"/> 
     </group> 
     <group name="Contacts"> 
      <add name="DayPhone" type="String"/> 
      <add name="DayPhoneExt" type="String"/> 
      <add name="EveningPhone" type="String"/> 
      <add name="EveningPhoneExt" type="String"/> 
      <add name="CellPhone" type="String"/> 
      <add name="Fax" type="String"/> 
     </group> 
     <group name="Company"> 
      <add name="Company" type="String"/> 
      <add name="Address" type="String"/> 
      <add name="City" type="String"/> 
      <add name="State" type="String"/> 
      <add name="PostalCode" type="String"/> 
      <add name="Phone" type="String"/> 
      <add name="Fax" type="String"/> 
      <add name="Website" type="String"/> 
     </group> 
     <group name="Preferences"> 
      <add name="Culture" type="String" defaultValue="en-US"/> 
      <add name="Newsletter" type="String"/> 
     </group> 
     </properties> 
    </profile> 

//membership-info.ascx 
    #region on page load get current profile 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     // Get Profile 
     if (!Page.IsPostBack) 
     { 
      if (Page.User.Identity.IsAuthenticated) 
      { 
       // get country names from app_code folder 
       // bind country names to the dropdown list 
       ddlCountries.DataSource = CountryNames.CountryNames.GetCountries(); 
       ddlCountries.DataBind(); 

       // get state names from app_code folder 
       // bind state names to the dropdown lists in address info and company info section 
       ddlStates1.DataSource = UnitedStates.StateNames.GetStates(); 
       ddlStates1.DataBind(); 
       ddlStates2.DataSource = UnitedStates.StateNames.GetStates(); 
       ddlStates2.DataBind(); 

       // get the selected user's profile based on query string 
       wProfile profile = wProfile.GetProfile(); 
       //profileCommon profile = Profile; 

       // Subscriptions 
       ddlNewsletter.SelectedValue = profile.GetProfileGroup("Preferences").GetPropertyValue("Newsletter").ToString(); 
       //ddlNewsletter.SelectedValue = profile.Preferences.Newsletter; 

       // Personal Info 
       txtFirstName.Text = profile.GetProfileGroup("Personal").GetPropertyValue("FirstName").ToString(); 
       txtLastName.Text = profile.GetProfileGroup("Personal").GetPropertyValue("LastName").ToString(); 
       ddlGenders.SelectedValue = profile.GetProfileGroup("Personal").GetPropertyValue("Gender").ToString(); 
       if ((DateTime)profile.GetProfileGroup("Personal").GetPropertyValue("BirthDate") != DateTime.MinValue) 
        txtBirthDate.Text = profile.GetProfileGroup("Personal").GetPropertyValue("BirthDate").ToString(); 
       ddlOccupations.SelectedValue = profile.GetProfileGroup("Personal").GetPropertyValue("Occupation").ToString(); 
       txtWebsite.Text = profile.GetProfileGroup("Personal").GetPropertyValue("Website").ToString(); 

       //txtFirstName.Text = profile.Personal.FirstName; 
       //txtLastName.Text = profile.Personal.LastName; 
       //ddlGenders.SelectedValue = profile.Personal.Gender; 
       //if (profile.Personal.BirthDate != DateTime.MinValue) 
       // txtBirthDate.Text = profile.Personal.BirthDate.ToShortDateString(); 
       //ddlOccupations.SelectedValue = profile.Personal.Occupation; 
       //txtWebsite.Text = profile.Personal.Website; 

       // Address Info 
       ddlCountries.SelectedValue = profile.GetProfileGroup("Address").GetPropertyValue("Country").ToString(); 
       txtAddress.Text = profile.GetProfileGroup("Address").GetPropertyValue("Address").ToString(); 
       txtAptNumber.Text = profile.GetProfileGroup("Address").GetPropertyValue("AptNumber").ToString(); 
       txtCity.Text = profile.GetProfileGroup("Address").GetPropertyValue("City").ToString(); 
       ddlStates1.SelectedValue = profile.GetProfileGroup("Address").GetPropertyValue("State").ToString(); 
       txtPostalCode.Text = profile.GetProfileGroup("Address").GetPropertyValue("PostalCode").ToString(); 

       //ddlCountries.SelectedValue = profile.Address.Country; 
       //txtAddress.Text = profile.Address.Address; 
       //txtAptNumber.Text = profile.Address.AptNumber; 
       //txtCity.Text = profile.Address.City; 
       //ddlStates1.SelectedValue = profile.Company.State; 
       //txtPostalCode.Text = profile.Address.PostalCode; 

       // Contact Info 
       txtDayTimePhone.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("DayPhone").ToString(); 
       txtDayTimePhoneExt.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("DayPhoneExt").ToString(); 
       txtEveningPhone.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("EveningPhone").ToString(); 
       txtEveningPhoneExt.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("EveningPhoneExt").ToString(); 
       txtCellPhone.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("CellPhone").ToString(); 
       txtHomeFax.Text = profile.GetProfileGroup("Contacts").GetPropertyValue("Fax").ToString(); 

       //txtDayTimePhone.Text = profile.Contacts.DayPhone; 
       //txtDayTimePhoneExt.Text = profile.Contacts.DayPhoneExt; 
       //txtEveningPhone.Text = profile.Contacts.EveningPhone; 
       //txtEveningPhoneExt.Text = profile.Contacts.EveningPhoneExt; 
       //txtCellPhone.Text = profile.Contacts.CellPhone; 
       //txtHomeFax.Text = profile.Contacts.Fax; 

       // Company Info 
       txbCompanyName.Text = profile.GetProfileGroup("Company").GetPropertyValue("Company").ToString(); 
       txbCompanyAddress.Text = profile.GetProfileGroup("Company").GetPropertyValue("Address").ToString(); 
       txbCompanyCity.Text = profile.GetProfileGroup("Company").GetPropertyValue("City").ToString(); 
       ddlStates2.SelectedValue = profile.GetProfileGroup("Company").GetPropertyValue("State").ToString(); 
       txbCompanyZip.Text = profile.GetProfileGroup("Company").GetPropertyValue("PostalCode").ToString(); 
       txbCompanyPhone.Text = profile.GetProfileGroup("Company").GetPropertyValue("Phone").ToString(); 
       txbCompanyFax.Text = profile.GetProfileGroup("Company").GetPropertyValue("Fax").ToString(); 
       txbCompanyWebsite.Text = profile.GetProfileGroup("Company").GetPropertyValue("Website").ToString(); 

       //txbCompanyName.Text = profile.Company.Company; 
       //txbCompanyAddress.Text = profile.Company.Address; 
       //txbCompanyCity.Text = profile.Company.City; 
       //ddlStates2.SelectedValue = profile.Company.State; 
       //txbCompanyZip.Text = profile.Company.PostalCode; 
       //txbCompanyPhone.Text = profile.Company.Phone; 
       //txbCompanyFax.Text = profile.Company.Fax; 
       //txbCompanyWebsite.Text = profile.Company.Website; 

       // Subscriptions 
       ddlNewsletter.SelectedValue = profile.GetProfileGroup("Preferences").GetPropertyValue("Newsletter").ToString(); 

       //ddlNewsletter.SelectedValue = profile.Preferences.Newsletter; 
      } 
     } 
    } 

    #endregion 

    #region Update current Profile Sub 

    public void SaveProfile() 
    { 
     if (Page.User.Identity.IsAuthenticated) 
     { 
      // get the selected user's profile 
      wProfile profile = wProfile.GetProfile(); 
      //ProfileCommon profile = Profile; 

      // Personal Info 
      profile.GetProfileGroup("Personal").SetPropertyValue("FirstName", txtFirstName.Text); 
      profile.GetProfileGroup("Personal").SetPropertyValue("LastName", txtLastName.Text); 
      profile.GetProfileGroup("Personal").SetPropertyValue("Gender", ddlGenders.SelectedValue); 
      if (txtBirthDate.Text.Trim().Length > 0) 
       profile.GetProfileGroup("Personal").SetPropertyValue("BirthDate", DateTime.Parse(txtBirthDate.Text)); 
      profile.GetProfileGroup("Personal").SetPropertyValue("Occupation", ddlOccupations.SelectedValue); 
      profile.GetProfileGroup("Personal").SetPropertyValue("Website", txtWebsite.Text); 

      //profile.Personal.FirstName = txtFirstName.Text; 
      //profile.Personal.LastName = txtLastName.Text; 
      //profile.Personal.Gender = ddlGenders.SelectedValue; 
      //if (txtBirthDate.Text.Trim().Length > 0) 
      // profile.Personal.BirthDate = DateTime.Parse(txtBirthDate.Text); 
      //profile.Personal.Occupation = ddlOccupations.SelectedValue; 
      //profile.Personal.Website = txtWebsite.Text; 

      // Address Info 
      profile.GetProfileGroup("Address").SetPropertyValue("Country", ddlCountries.SelectedValue); 
      profile.GetProfileGroup("Address").SetPropertyValue("Address", txtAddress.Text); 
      profile.GetProfileGroup("Address").SetPropertyValue("AptNumber", txtAptNumber.Text); 
      profile.GetProfileGroup("Address").SetPropertyValue("City", txtCity.Text); 
      profile.GetProfileGroup("Address").SetPropertyValue("State", ddlStates1.Text); 
      profile.GetProfileGroup("Address").SetPropertyValue("PostalCode", txtPostalCode.Text); 

      //profile.Address.Country = ddlCountries.SelectedValue; 
      //profile.Address.Address = txtAddress.Text; 
      //profile.Address.AptNumber = txtAptNumber.Text; 
      //profile.Address.City = txtCity.Text; 
      //profile.Address.State = ddlStates1.Text; 
      //profile.Address.PostalCode = txtPostalCode.Text; 

      // Contact Info 
      profile.GetProfileGroup("Contacts").SetPropertyValue("DayPhone", txtDayTimePhone.Text); 
      profile.GetProfileGroup("Contacts").SetPropertyValue("DayPhoneExt", txtDayTimePhoneExt.Text); 
      profile.GetProfileGroup("Contacts").SetPropertyValue("EveningPhone", txtEveningPhone.Text); 
      profile.GetProfileGroup("Contacts").SetPropertyValue("EveningPhoneExt", txtEveningPhoneExt.Text); 
      profile.GetProfileGroup("Contacts").SetPropertyValue("CellPhone", txtCellPhone.Text); 
      profile.GetProfileGroup("Contacts").SetPropertyValue("Fax", txtHomeFax.Text); 

      //profile.Contacts.DayPhone = txtDayTimePhone.Text; 
      //profile.Contacts.DayPhoneExt = txtDayTimePhoneExt.Text; 
      //profile.Contacts.EveningPhone = txtEveningPhone.Text; 
      //profile.Contacts.EveningPhoneExt = txtEveningPhoneExt.Text; 
      //profile.Contacts.CellPhone = txtCellPhone.Text; 
      //profile.Contacts.Fax = txtHomeFax.Text; 

      // Company Info 
      profile.GetProfileGroup("Company").SetPropertyValue("Company", txbCompanyName.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("Address", txbCompanyAddress.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("City", txbCompanyCity.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("State", ddlStates2.SelectedValue); 
      profile.GetProfileGroup("Company").SetPropertyValue("PostalCode", txbCompanyZip.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("Phone", txbCompanyPhone.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("Fax", txbCompanyFax.Text); 
      profile.GetProfileGroup("Company").SetPropertyValue("Website", txbCompanyWebsite.Text); 

      //profile.Company.Company = txbCompanyName.Text; 
      //profile.Company.Address = txbCompanyAddress.Text; 
      //profile.Company.City = txbCompanyCity.Text; 
      //profile.Company.State = ddlStates2.SelectedValue; 
      //profile.Company.PostalCode = txbCompanyZip.Text; 
      //profile.Company.Phone = txbCompanyPhone.Text; 
      //profile.Company.Fax = txbCompanyFax.Text; 
      //profile.Company.Website = txbCompanyWebsite.Text; 

      // Subscriptions 
      profile.GetProfileGroup("Preferences").SetPropertyValue("Newsletter", ddlNewsletter.SelectedValue); 

      //profile.Preferences.Newsletter = ddlNewsletter.SelectedValue; 

      // this is what we will call from the button click 
      // to save the user's profile 
      profile.Save(); 
     } 
    } 

    #endregion 
相關問題