How to assign Profile values?

前端 未结 10 744
别那么骄傲
别那么骄傲 2020-11-22 08:49

I don\'t know what I am missing, but I added Profile properties in the Web.config file but cannot access Profile.Item in the code or create a new profile.

10条回答
  •  萌比男神i
    2020-11-22 09:17

    When you create a new Web site project in Visual Studio then the object that is returned from Profile will be (automatically) generated for you. When you create a Web application project or an MVC project, you will have to roll your own.

    This probably sounds more difficult than it is. You need to do the following:

    • Create a database using aspnet_regsql.exe This tool is installed along with the .NET framework.
    • Write a class that derives from ProfileGroupBase or install the Web Profile Builder (WPB) that can generate the class for you from the definition in Web.Config. I have been using WPB for a while and up until now it has done what is expected of it. If you have a lot of properties, using WPB can save quite a bit of time.
    • Make sure the connection to the database is properly configured in Web.Config.
    • Now you are set to create an instance of your profile class (in the controller)
    • You will probably need the profile property values in your views. I like to pass the profile object itself along to the view (not individual properties).

提交回复
热议问题