开发者

.Net SQL Membership Provider custom provider property

开发者 https://www.devze.com 2023-01-31 11:38 出处:网络
<profile> <providers> &l开发者_开发问答t;clear/> <add name=\"AspNetSqlProfileProvider\" type=\"System.Web.Profile.SqlProfileProvider\" connectionStringName=\"ApplicationServices\" ap
<profile>      
  <providers>
    &l开发者_开发问答t;clear/>
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
  </providers>
  <properties>
    <add name="FirstName"/>
    <add name="LastName"/>
  </properties>
</profile>  

I have the code snippet above in my webconfig file. I am attempting to set the FirstName property in codebehind on a register.aspx page. Like this:

Profile.FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;  

VS says Profile is in System.Web.Profile Namespace. I then use it like this "System.Web.Profile.FirstName", but says first name does not exist in System.Web.Profile.FirstName namespace.

How do I set the property and later retrieve it?


Profile should be a property with an autogenerated class based on System.Web.Profile.ProfileBase which contains the members you defined in your web.config file. Here is the link on msdn: http://msdn.microsoft.com/de-de/library/system.web.profile.profilebase.aspx

But i can remember that i also had the problem, that the file is not generated by visual studio. I found this post where you can see a WebProfile generator as an extension for the build process. Maybe that can help you.


In order to get strongly typed access to the profile items you need to use a tool such as the Web Profile Builder.

In Website projects Asp.net automatically creates the strongly typed proxy classes but they are not automatically created in Web Application projects.


You can do something like:

ProfileCommon p = (ProfileCommon)ProfileBase.Create(username, true);

p.FirstName = "firstname";

p.Save();

if the user already has a profile, the create call will return the existing profile, else it will create a new profile.

ProfileCommon is a autogenerated class.

0

精彩评论

暂无评论...
验证码 换一张
取 消