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.
Asp.net-mvc – How to assign Profile values
asp.netasp.net-membershipasp.net-mvcprofile
Related Question
- Jquery – How to format a Microsoft JSON date
- .net – ASP.NET Web Site or ASP.NET Web Application
- Asp.net-mvc – ASP.NET MVC – Set custom IIdentity or IPrincipal
- Bash – How to reload .bashrc settings without logging out and back in again
- Iphone – A valid provisioning profile for this executable was not found for debug mode
- Cannot read configuration file due to insufficient permissions
- IIS 500.19 with 0x80070005 The requested page cannot be accessed because the related configuration data for the page is invalid error
Best Solution
I had the same problem today, and learned a lot.
There are two kinds of project in Visual Studio -- "Web Site Projects" and "Web Application Projects." For reasons which are a complete mystery to me, Web Application Projects cannot use Profile. directly... the strongly-typed class is not magically generated for you from the Web.config file, so you have to roll your own.
The sample code in MSDN assumes you are using a Web Site Project, and they tell you just to add a
<profile>
section to yourWeb.config
and party on withProfile.
property, but that doesn't work in Web Application Projects.You have two choices to roll your own:
(1) Use the Web Profile Builder. This is a custom tool you add to Visual Studio which automatically generates the Profile object you need from your definition in Web.config.
I chose not to do this, because I didn't want my code to depend on this extra tool to compile, which could have caused problems for someone else down the line when they tried to build my code without realizing that they needed this tool.
(2) Make your own class that derives from
ProfileBase
to represent your custom profile. This is easier than it seems. Here's a very very simple example that adds a "FullName" string profile field:In your web.config:
In a file called AccountProfile.cs:
To set a profile value:
To get a profile value