J'ai ajouté une nouvelle propriété booléenne à ma classe de profil.Comment définir une valeur par défaut pour une nouvelle propriété de profil pour les utilisateurs existants dans ASP.NET?
Je n'arrive pas à trouver un moyen d'avoir sa valeur par défaut.
Profile.ShowDocumentsNotApplicable
renvoie false lorsqu'ils ne sont pas explicitement la valeur true ...
contenu web.config:
<!-- snip -->
<profile inherits="Company.Product.CustomerProfile">
<providers>
<clear />
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
</profile>
<!-- snap -->
CustomerProfile:
public class CustomerProfile: ProfileBase
{
private bool _showDocumentsNotApplicable = true;
public bool ShowDocumentsNotApplicable
{
get { return Return("ShowDocumentsNotApplicable", _showDocumentsNotApplicable); }
set { Set("ShowDocumentsNotApplicable", value,() => _showDocumentsNotApplicable = value); }
}
private T Return<T>(string propertyName, T defaultValue)
{
try
{
return (T)base[propertyName];
}
catch (SettingsPropertyNotFoundException)
{
return defaultValue;
}
}
private void Set<T>(string propertyName, T setValue, System.Action defaultAction)
{
try
{
base[propertyName] = setValue;
}
catch (SettingsPropertyNotFoundException)
{
defaultAction();
}
}
}