0

我正在尝试使用 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>
4

3 回答 3

3

添加配置文件时,您将其称为 SqlProvider 而不是 SqlServices。(您在上面使用的默认配置文件提供程序名称)

于 2009-04-07T15:55:55.173 回答
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();
于 2009-04-07T15:56:43.957 回答
1

如果您使用的是 Web 应用程序项目,您将需要自己实现配置文件。配置文件只能与网站选项一起使用。Web 应用程序项目没有像网站项目那样将 Profile 对象自动添加到每个页面,因此我们无法获得对 web.config 文件中定义的配置文件属性的强类型编程访问。

因此,如果您使用的是 Web 应用程序项目,这应该会有所帮助:

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

但是,如果您使用的是网站项目,那么 Scott Guthrie 的这篇文章应该会引导您朝着正确的方向前进:

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

:-)

于 2009-05-08T03:05:31.807 回答