3

I look through the ASP.NET 4.0 online cource, just one of the first lessons.

I have Visual Studio 2012 for Web installed, and it has ASP.NET 4.5 on board.

In order to access some web.config properties, guy in the course writes following line:

Profile.Preferences.MyParameter = "MyValue";

but when I type the same thing, it gives me an error: Profile element doesn't exist in the current context. And when I'm trying to access System.Web.Profile.Preferences, it says that Type or namespace "Preferences" is missing in System.Web.Profile.

Can anyone please tell what's happening? Is ASP.NET 4.5 the reason of this behavior, and if yes - how can I access the same web.config properties is ASP.NET 4.5?

My web.config looks like that:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <profile>
      <properties>
        <group name="Preferences">
          <add name="MyParameter"/>
        </group>
      </properties>
    </profile>
  </system.web>
</configuration>

UPDATE: I've tried to implement the second solution from Joel Spolsky's answer: How to assign Profile values?

But the code doesn't work for me. The following method crahes:

static public AccountProfile CurrentUser
    {
        get { return (AccountProfile)
                     (ProfileBase.Create(Membership.GetUser().UserName)); }
    }

It happens because Membership.GetUser() returns null. What Can I do with that?

Community
  • 1
  • 1
Dmitry Samoylov
  • 1,228
  • 3
  • 17
  • 27
  • What are you trying to do? You don't appear to be trying to access web.config properties. You can access the profile section of a config using [ProfileSection](http://msdn.microsoft.com/en-us/library/system.web.configuration.profilesection(v=vs.100).aspx). – MikeSmithDev Jan 28 '14 at 15:41
  • @MikeSmithDev I've added the web.config contents to the question. I need to assign a value to the `"MyParameter"`. – Dmitry Samoylov Jan 28 '14 at 15:47
  • You might try resolving your Membership.GetUser() problem first. Once that is solved, you may find that your profile problem was related and/or resolved. – yougotiger Jan 28 '14 at 19:39

1 Answers1

0

From your description I believe the problem is that it is referencing improperly so it cannot find what you are trying to access.

Im guessing you tried: How to assign Profile values?

As you referenced the author the first part of Joel Spolskys answer is which application type are you using??? There are two kinds of project in Visual Studio -- "Web Site Projects" and "Web Application Projects." There are several other types of projects but these are the main "web" applications.

The exact details of how to access properties varies heavily based on framework and application type. For example if your in Windows forms you have an app.config or if your in a web application you would have a web.config. Did you make the web.config or was it there and you have edited it?

I could try to explain how to access the properties, but if its not for the same type as your application it won't work anyway.

Can you start by checking this by determine project type in visual studio?

If your in the wrong project type just try to make a new project in the correct type and see if your existing code works then.

Community
  • 1
  • 1
JPK
  • 1,324
  • 2
  • 14
  • 25