0

I have a page called ProfileInfo.aspx and the codebind looks like this -

            using System;
            using System.Web;

            namespace myservice
            {
                public partial class ProfileInfo : System.Web.UI.Page
                {
                    protected void Page_Load(object sender, EventArgs e)
                    {

                        // if no postback but user is authenticated, grab info from database
                        if (!IsPostBack)
                        {
                            if (System.Web.Profile.**IsAnonymous** == false)
                            {

                            }


                        }


                    }

                    protected void btnSave_Click(object sender, EventArgs e)
                    {

                    }
                }
            }

And I am getting an error from the Profile.IsAnonymous statement, as follows -

The type or namespace name 'IsAnonymous' does not exist in the namespace 'System.Web.Profile' (are you missing an assembly reference?)

What am I doing wrong? Do I need to add a .NET dll reference to the web application project? I tried to look for System.Web.Profile but there is no such DLL. Please help and thanks in advance.

Arunabh Das
  • 13,212
  • 21
  • 86
  • 109

4 Answers4

1

You dont need an assembly reference.

The System.Web.Profile namespace exists in the System.Web assembly (which is already added to web applications by default).

IsAnonymous is a property of the ProfileInfo class.

Do it like this:

if (Profile.IsAnonymous == false)
{
    // your code here
}

Taken from MSDN:

When your application runs, ASP.NET creates a ProfileCommon class, which is a dynamically generated class that inherits the ProfileBase class. The dynamic ProfileCommon class includes properties created from the profile property definitions you specify in your application configuration. An instance of this dynamic ProfileCommon class is then set as the value of the Profile property of the current HttpContext and is available to pages in your application.

RPM1984
  • 72,246
  • 58
  • 225
  • 350
1

You can use Context.Profile.IsAnonymous but your intention is probably to read values from profile.

You can't use Profile directly in web applications. See How to assign Profile values?

Community
  • 1
  • 1
Pavel Chuchuva
  • 22,633
  • 10
  • 99
  • 115
0

System.Web.Profile is a namespace, not a class. You'll need a reference to an actual Profile to check if it's anonymous.

3Dave
  • 28,657
  • 18
  • 88
  • 151
0

Try

Context.Profile.IsAnonymous
matt-dot-net
  • 4,204
  • 21
  • 24