/Download/CustomFileDownload.ashx Endpoint

Is the /Download/CustomFileDownload.ashx Endpoint designed to be utilized by constituents who do not have a CRM user mapping?

We have a BBIS site which constituents can login to and download a pdf from our BB database. If the constituent is mapped to a CRM user the download works but for any constituent not mapped to a CRM user then we receive authorization issues.

I'm trying to understand if we should be using the /Download/CustomFileDownload.ashx Endpoint for this or if there is other BB functionality better suited for file downloads.

Comments

  • @Nick Preshaw
    Hi Nick!

    I have had similar issues. I don't think the Downloadfile handler works for unmapped users. I ended up writing a custom handler to dish out files, which isn't as bad as it seems.

    1. Write a new class that inherits from BBNCExtensions.CustomHandlers.CustomHandlerBase
    2. In that class, override the “ProcessRequest” method with code similar to this.

    Public Overrides Sub ProcessRequest(context As HttpContext)
    Dim userfilename As String = String.Empty
    Try
    Dim request As HttpRequest = HttpContext.Current.Request

    userfilename = request.QueryString("userfilename")

    If Not String.IsNullOrEmpty(userfilename) Then
    'this is a CRM view form, which takes a file name and returns it as a binary output field
    Dim rep = CRMConnection.LoadForm(New Guid("356fc11d-97b3-4028-91d5-18b17a6431da"), userfilename)
    Dim fileContents As Byte() = rep.DataFormItem.Values("FILE").Value
    If fileContents Is Nothing OrElse fileContents.Length = 0 Then
    context.Response.Write("Sorry, no file found.")
    Else
    context.Response.ContentType = "application/pdf"
    context.Response.BinaryWrite(fileContents)
    End If
    End If

    Once that is deployed, you can invoke the handler and pull down the requested file with a URL like the one below. In the case of PDFs, I've had good success with embedding them inline as iframes. Ping me if you'd like to talk this over further.