Generating Links to Files and Assets Located in Secure Folders

Overview

On some occasions, a user may want to know the full path to a file on their site, and generate a link to it directly from the backend. This can be achieved by exploring the <Files> table in the DB and joining the folder and filename value to the site URL.

However, a user must note that there are two types of folders, secure and standard. The links from these two folders differ in the fact that secure folder links are autogenerated using LinkCLicks and the FileTicket attribute by default.

Here are examples of links from the two folders:

  • Secure Folder Link:
    http://siteurl/LinkClick.aspx?fileticket=KY7zLilddKM%3d&portalid=0&language=en-U
  • Standard Folder Link:
    http://siteurl/Portals/0/Files_Standard/Email%20Retention%20Implementation.pdf?ver=2019-05-16-090653-263

When a user creates a folder as a secure folder, DNN will append a ".resources" extension to any file within that folder. As ".resources" is mapped to the 404-handler automatically by asp.net it means that a request to that file will be ignored i.e., if a user knew or could guess the URL, a request for "www.siteurl.com/portals/0/wages.xls" would serve up that file. However a request for "www.siteurl.com/portals/0/wages.xls.resources" would be denied.

This functionality is hardcoded in the system and cannot be changed as it serves to protect files located in secure folders against anonymous downloads. Since the FileTicket attribute is a secure value generated by DNN in execution time and is not stored in the DB, generating links using information in the DB for files located in secure folders will result in a 404 error, as the file will not be found.

This article will provide you with the steps to enable you to autogenerate links to files that are currently located in secure folders.

Environment

DNN 9+

Process

  1. Move the content of the assets from a secure folder into a standard folder. This process has to be performed manually.
  2. After the files have been moved, use the following SQL query to generate the link to the files contained in a particular folder:
    ​select concat('http://',s.settingvalue,'/Portals/<portalid>/',f.folder,f.filename) as filepath from files f, portalsettings s where f.portalid=<portalid> and s.PortalID=<portalid> and f.folder like '%<foldername>%' and s.SettingName='DefaultPortalAlias';
    NOTE: The Portal ID value in the query <portalid> should be replaced with the actual PortalID value from the site. This value can be found in the Persona Bar, by going to Manage -> Sites, and setting the view option to ListView. The value for SiteID in the page is the same as PortalID in the DB.

Confirmation

You should now be now able to generate links by exploring the <Files> table in the DB and joining the folder and filename value to the site URL.

 

 

 

Comments

0 comments

Article is closed for comments.