Lord Vermillion
Lord Vermillion

Reputation: 5414

C# MVC display PDF in App Data with HTML object

I want to display PDF files in my View, the PDF files are stored in my App Data folder.

If i pass the directPath in the model like this: C:\Projekt\x\App_Data\Guides\Information.pdf i get PDF error in my view.

<div class="embed-responsive embed-responsive-16by9">
    <object class="embed-responsive-item" data="@Model.directPath" type="application/pdf">

        <p>PDF error</p>

    </object>
</div>

However if i add a Content folder to my c# project and put the file there, and change the path to data="Content/Information.pdf" then the PDF will display.

How can i access the pdf files in App Data?

Upvotes: 0

Views: 1084

Answers (2)

Shanshan Bi
Shanshan Bi

Reputation: 171

App_Data folder contains the application's local data storage. It usually contains data storage in the form of files (such as Access Microsoft or SQL Server Express Microsoft, XML files, text files, and any other files supported by the application). The contents of this folder are not processed by ASP.NET. This folder is the default location for the ASP.NET provider to store its own data. For data security, this folder is added to the request filter module to be set to deny access,Want to visit, to carry out the operation.

  • Open Directory C:\Windows\System32\inetsrv\config
  • Find applicationHost.config and Open it(Pay attention to use the administrator to open the way)
  • Find security/requestFiltering/hiddenSegments
  • Deletes the item <add segment="App_Data" /> and save

Upvotes: 0

Sara Murtuzayeva
Sara Murtuzayeva

Reputation: 60

Try to use Absolute path to this directory in your code. Something like

HttpContext.Server.MapPath("~/App_Data/Information.pdf");

This path syntax depends on your MVC model version.

Upvotes: 1

Related Questions