2009-04-07 70 views
0

我試圖使用ASP.net型材我跟着一些指令,這意味着我有我需要幫助配置ASP.net簡介

  1. 成立ASPNETDB(使用的SQLExpress 2005)
  2. 一配置(在web.config)配置文件提供者
  3. 定義的一些屬性
  4. 啓用驗證

但我似乎無法使用像代碼(即IntelliSense不喜歡它)

Profile.UserCustomContent = "Hi Mom"; 

很明顯我錯過了什麼重要,但我看不到,請幫我...

這裏有一些剪從我web.config

<connectionStrings> 
<add name="SqlServices" 
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalogue=aspnetdb" /> 
</connectionStrings> 

<system.web> 
<authentication mode="Windows" /> 
<authorization> 
<deny users="?"/> 
</authorization> 

<profile enabled="true" defaultProvider="SqlServices"> 
<providers> 
<clear/> 
<add name="SqlProvider" type="System.Web.Profile.SqlProfileProvider" 
connectionStringName="SqlServices" applicationName="MyInternalApplication" /> 
</providers> 


<properties> 
<add name="UserSearchFilterOptions" type="String" /> 
<add name="UserCustomContent" type="String"/> 
</properties> 
</profile> 
</system.web> 
+0

我發現Asp.Net入門套件非常適合搞清楚這樣的事情......還.. http://msdn.microsoft.com/en -us/asp.net/aa336558。aspx – madcolor 2009-04-07 16:23:09

回答

1

如果您正在使用Web應用程序項目,則需要自行實施配置文件。配置文件只能與網站選項一起使用。與Web站點項目一樣,Web應用程序項目沒有自動添加到每個頁面的Profile對象,因此我們無法獲得對web.config文件中定義的配置文件屬性的強類型編程訪問。

因此,如果您使用的是Web應用程序項目,這應該幫助:

http://code.msdn.microsoft.com/WebProfileBuilder

但是,如果您使用的是網站項目,那麼這篇文章由斯科特·格思裏應該引領你在正確的方向:這個對我自己的博客文章的一個

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

更多細節:

http://www.codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx

:-)

3

當您添加配置文件時,您將其稱爲SqlProvider而不是SqlServices。 (您在上面使用的默認配置文件提供程序名稱)

+0

哈哈,還是卡住了,但是這肯定會有進步:D – inspite 2009-04-07 16:20:18

1

這就是我的做法..也許您的情況有不同的方式。

VB - 新用戶。(是真爲IsAuthenticated值)

Dim profile As ProfileCommon = ProfileCommon.Create(myUser.UserName, True) 
profile.UserCustomContent = "customcontent" 

VB - 現有用戶...

Dim profile As ProfileCommon 
profile = Profile.GetProfile(myUser.UserName) 
profile.UserCustomContent = "customcontent" 

C# - 新用戶

ProfileCommon profile = (ProfileCommon) ProfileCommon.Create(myUser.UserName, true); 
profile.UserCustomContent = "customcontent"; 
profile.Save(); 

C# - 現有用戶

ProfileCommon profile; 
profile = Profile.GetProfile(myUser.UserName); 
profile.UserCustomContent = "customcontent"; 
profile.Save();