在ASP.NET网站中,可以通过对Web.Config部分进行一些简短添加来为用户配置文件添加自动连接的魔术属性。ASP.NET Web App的配置文件提供程序 - 自动有线属性
因此,例如一些这样的XML。
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
<properties>
<add name="Name" allowAnonymous="true"/>
<add name="VisitedOn" type="System.DateTime" allowAnonymous="true"/>
</properties>
</profile>
你最终可以做到这一点。无需声明任何进一步的代码。
Profile.Name = "Some Test Value";
Profile.VisitedOn = DateTime.Now;
Profile.Save();
我试图复制在ASP.NET Web应用此功能,甚至不能似乎找到底部型材声明更不用说自定义属性。
但是我发现System.Web.Profile.DefaultProfile.Properties
确实包含了我在Web.Config中定义的自定义声明属性。
那么我可能会出错?在Web应用程序中获取自动连线属性的过程是什么?