More in this section

Forums / Bugs & Issues / Code wont run unless I'm logged in

Code wont run unless I'm logged in

2 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    07 Jun 2011
    Link to this post
    I just want to update the ViewCount...

    Document doc = lm.GetDocument(documentID);
                doc.ViewsCount = doc.ViewsCount + 1;
                lm.SaveChanges();

    But when the follow executes on an anon user I get a YSOD...how do I get around this one?



    You are not authorized to 'Modify library and manage documents' ('Document').

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.UnauthorizedAccessException: You are not authorized to 'Modify library and manage documents' ('Document').

    ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

    To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

    Source Error:

    Line 56:             Document doc = lm.GetDocument(documentID);
    Line 57:             doc.ViewsCount = doc.ViewsCount + 1;
    Line 58:             lm.SaveChanges();
    Line 59:             
    Line 60:             Response.Redirect(lm.GetItemUrl(doc) + doc.Extension +  "?Status=Master");

    Source File: C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\Publications\Publications.ascx.cs    Line: 58
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Jun 2011
    Link to this post
    Hello Steve,

    The code fails, because you cannot make modifications to an object with the api if the current user ( which in your case is anonymous ) is not granted with modify permissions.
    You can use Manager.Provider.SuppressSecurityChecks = true; in your code to allow SaveChanges to be processed then set SuppressSecurityChecks back to false which is its initial state

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered