2010-12-16 106 views
0
<profile>  
    <providers> 
    <clear/> 
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/> 
    </providers> 
    <properties> 
    <add name="FirstName"/> 
    <add name="LastName"/> 
    </properties> 
</profile> 

淨SQL成員資格提供自定義提供財產

我的代碼片段上方我的webconfig文件。我試圖在register.aspx頁面上的代碼隱藏中設置FirstName屬性。像這樣:

Profile.FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text; 

VS表示Profile在System.Web.Profile命名空間中。然後我使用它像這樣的「System.Web.Profile.FirstName」,但是在System.Web.Profile.FirstName命名空間中不存在名字。

如何設置屬性並稍後檢索它?

+0

你可以發佈多一點你的代碼,特別是我期待看到'Profile'是什麼? – CodingGorilla 2010-12-16 16:40:31

回答

0

爲了獲得對配置文件項目的強類型訪問,您需要使用諸如Web Profile Builder之類的工具。

在網站項目中Asp.net自動創建強類型代理類,但它們不會自動在Web應用程序項目中創建。

+0

使用VS 2010有沒有使用WebProfileBuilder有所作爲?我問,因爲我運行了WebProfileBuilder。我在我的csproj中添加了Import Project行。當我打開解決方案並編譯時,我沒有被提示正常加載我的項目。安裝MSI和構建項目是否會導致創建WebProfile類?沒有看到任何創造。什麼是設置/訪問配置文件屬性的代碼。這似乎沒有設置它:System.Web.Profile.ProfileBase.Properties [「FirstName」]。Name =((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl(「FirstName」))。 – obautista 2010-12-16 17:56:25

0

你可以這樣做:

的ProfileCommon P =(的ProfileCommon)ProfileBase.Create(用戶名,真實);

p.FirstName =「firstname」;

p.Save();

如果用戶已有配置文件,create call將返回現有配置文件,否則會創建一個新配置文件。

ProfileCommon是一個自動生成的類。

相關問題