Question

Looking to know what best practice is for the following. I am running an asp.net mvc 4 site.

I have 2 static PDF documents that a user to my site can download. The path to the documents are based on different criteria. I have 3 options to generate the path to the file.

  1. Process it in the controller when the page loads and pass the path in my view model to my razor view and add it to the href tag of an anchor link

  2. Have a controller action that is called when a user clicks a link to return a FileResult.

  3. Have an HtmlHelper that returns the path to the file.

Which one above is best practice? I am lean towards number 1 but would like feedback as architecturally the best option and also the least impact on performance.

Was it helpful?

Solution

I think that #2 is the best option. First, you don't have to bypass the routing. Second, I think it is always more secure if you don't reveal the actual structure of your file hierarchy. And, lastly, if you ever change the location of the files, your links won't break - you can just point your controller to the new file location.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top