我在這裏碰到了一個泡菜。我有一個自定義配置文件,我在兩個應用程序中使用了相同的解決方案。第一個是構建的Web應用程序,用於將舊的.net應用程序中的一組自定義用戶配置文件和屬性導入到.net成員身份,角色,配置文件表中。我構建了一個從配置文件繼承的配置文件公共類。這兩個應用程序在其命名空間中都有相同類的副本。.net配置文件提供程序和自定義配置文件。設置屬性「'未找到。
using System;
using System.Web.Security;
using System.Web.Profile;
using System.Collections.Specialized;
namespace WebProject
{
public class ProfileCommon : ProfileBase
{
public static ProfileCommon GetUserProfile(string username)
{
return Create(username) as ProfileCommon;
}
public static ProfileCommon GetUserProfile()
{
return Create(Membership.GetUser().UserName) as ProfileCommon;
}
[SettingsAllowAnonymous(false)]
public string FirstName
{
get
{
return base["FirstName"] as string;
}
set
{
base["FirstName"] = value;
}
}
[SettingsAllowAnonymous(false)]
public string LastName
{
get
{
return base["LastName"] as string;
}
set
{
base["LastName"] = value;
}
}
[SettingsAllowAnonymous(false)]
public string Email
{
get
{
return base["Email"] as string;
}
set
{
base["Email"] = value;
}
}
[SettingsAllowAnonymous(false)]
public StringCollection Sites
{
get
{
return base["Sites"] as StringCollection;
}
set
{
base["Sites"] = value;
}
}
}
}
我在我的web配置文件中的配置文件提供程序部分看起來像這樣。
<profile defaultProvider="WebProjectProfileProvider" inherits="WebProject.ProfileCommon">
<providers>
<clear />
<add name="WebProjectProfileProvider" applicationName="/" type="System.Web.Profile.SqlProfileProvider" connectionStringName="Test"/>
</providers>
</profile>
如果我使用一個應用程序來執行用戶導入,另一個使用的會員,角色和我創建的配置文件會變成這樣導致「設置屬性‘’沒有被發現。」錯誤?我似乎無法查明錯誤發生的位置以及我已檢查的一些最常見原因。這是我第一次在如此大規模的.net中使用這個功能。任何幫助是極大的讚賞。
謝謝。
你在哪裏指定了可用的設置名稱和類型?如果我沒有記錯,它們也應該在Web.config文件中指定。 – Venemo
指定的名稱和類型在Profile Common類本身內。因爲我在web.config中使用。它會自動知道使用上面列出的Profile Common類中的類型。如果我不使用「inherits」屬性,則.net框架將在運行時拋出一個錯誤,指出該屬性未被聲明。如果不使用inherits屬性,則開發人員必須使用節點在web.config文件中聲明名稱和類型。 –
gsirianni