More in this section

Forums / Developing with Sitefinity / Downloading documents

Downloading documents

2 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    06 Jun 2011
    Link to this post
    I want to have some LinkButtons to download files, and on click of those I'd like to update the viewcount of the document.

    So that part I can do...(quite nice with fluent)

      How do I get the download URL of the document (the embed link we get in the backend).  Is it safe to just call the standard URL method, and append the extension and ?Status=Master or is there a better way.

    **EDIT**
    Ok, so turns out the updating viewcount fails when I try it as a user not logged in...?

    Server Error in '/' Application.

    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

    Stack Trace:

    [UnauthorizedAccessException: You are not authorized to 'Modify library and manage documents' ('Document').]
       DynamicModule.ns.Wrapped_OpenAccessLibrariesProvider_d00af4c87f854b479dd3d3f88b3444e1.CommitTransaction() +342
       Telerik.Sitefinity.Data.ManagerBase`1.SaveChanges() +53
       SitefinityWebApp.UserControls.Publications.Publications.OnDownload_Click(Object sender, EventArgs e) in C:\My Dropbox\Projects\Leap\OCFP\Web\UserControls\Publications\Publications.ascx.cs:58
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +155
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1


    Steve
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    09 Jun 2011
    Link to this post
    Hi 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.

    Best wishes,
    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