System.Configuration.Provider.ProviderException: This property cannot be set for anonymous users. RRS feed

  • Question

  • User2076542161 posted

    Hey!! I have created a simple web page, that is generating the error mentioned above. Can you please help me out in in??
    Here is more with this error when displayed on browser:

    Line 10:     protected void Page_Load(object sender, EventArgs e)
    Line 11:     {
    Line 12: Profile.preferences.Theme = "Retro"; Line 13:         this.LiteralTheme.Text = Profile.preferences.Theme;
    Line 14:     }
    [ProviderException: This property cannot be set for anonymous users.]
       System.Web.Profile.ProfileBase.SetInternal(String propertyName, Object value) +2371783
       System.Web.Profile.ProfileBase.set_Item(String propertyName, Object value) +80
       ProfileGrouppreferences.set_Theme(String value) +36
       ProfileObject.Page_Load(Object sender, EventArgs e) in c:\Users\AADIL FAROOQUI\Documents\Visual Studio 2012\WebSites\Lesson4\ProfileObject.aspx.cs:12
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
       System.Web.UI.Control.OnLoad(EventArgs e) +92
       System.Web.UI.Control.LoadRecursive() +54
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
    and here is the web.config file:


    <compilation debug="false" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <group name="preferences">
    <add name="Theme"/>
    <add name="Currency"/>



    Friday, March 8, 2013 2:00 AM


  • User-837620913 posted

    A couple of issues. First, to set the property on anonymous users, you need to change your profile config to enable it, like this:

      <anonymousIdentification enabled="true"/>   
      <trust level="Medium"/>   
        <profile >
            <add name="Name" allowAnonymous="true" />
            <add name="Age" allowAnonymous="true" type="System.Int16"/>
        <compilation debug="true"/>

    Second, you can't set the profile in Page_Load. It has to be set in PreInit. You can add the following to global.asax:

    protected void Application_PreRequestHandlerExecute(object sender, System.EventArgs e)
        Page p = HttpContext.Current.Handler as Page;
        if (p != null)
            ProfileCommon pb = HttpContext.Current.Profile as ProfileCommon;
            p.StyleSheetTheme = pb.Theme; // whatever theme is

    For more details on these issues, see the answers in this thread: http://forums.asp.net/t/1225752.aspx/1/10?System+Configuration+Provider+ProviderException+This+property+cannot+be+set+for+anonymous+users

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 8, 2013 6:00 AM