0

i am working in MVC and i am trying to preview a pdf from web-server but it is showing error as :

Not allowed to load local resource: file://web-server/images/1324/Sample%20Document.pdf

<iframe src="@Model.urlpath" width="650" height="350" style="border: 1px solid #ccc; margin:10px 5px !important;"></iframe>

i am trying to get this url path from web server to local application

chaitanya k
  • 199
  • 1
  • 3
  • 14

1 Answers1

0

Default security setting for modern browsers disallows usage of file:// protocol in elements with src attribute, including iframe (related issues here and here, see also same origin policy). Use server's relative path instead as in example below.

Controller

var model = new ViewModel();
model.urlpath = string.Format("~/images/{0}/{1}", "1324", "Sample_Document.pdf");

View

<iframe src="@Url.Content(Model.urlpath)" width="650" height="350" style="border: 1px solid #ccc; margin:10px 5px !important;"></iframe>

Or use hardcoded virtual path inside @Url.Content and just pass file name from viewmodel property:

Controller

var model = new ViewModel();
model.FileName = "Sample_Document.pdf";

View

<iframe src="@Url.Content("~/images/1324" + Model.FileName)" width="650" height="350" style="border: 1px solid #ccc; margin:10px 5px !important;"></iframe>
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61