Url.Content on Azure

邮差的信 提交于 2019-12-08 07:05:00

问题


I have an ASP.NET MVC 2 application that has page with a link to a pdf file

<a href="<%= Url.Content("~/Downloads/test1.pdf") %>">test1</a>

Downloads directory is at MVCApplication1/Downloads

This works fine locally and on ISS, but returns a page not found when uploaded to Azure.


回答1:


Check the path that is being emitted in the HTML. Its likely relative to the Azure datacenter/cluster, and is meaningless to your client if your client is outside Azure.

If you see something like "http://RD1204900029029/Downloads/test1.pdf", thats your issue. You'll need to emit the actual path using application logic to account for some of the magic the load-balancer does on your behalf.

Best way to use URL information provided by the request itself. I'm not an ASP.NET master by any means, so there may be a cleaner way to do this (similar to Url.Content) but this will work

Try

HttpContext.Current.Request.Url.Host

so

<%
    var host = System.Web.HttpContext.Current.Request.Url.Host;
%>

<a href="<%= host + "/Downloads/test1.pdf" %>">test1</a>



回答2:


In visualstudio in the pdf properties had to change the Build Action to Content and Copy to Output Dir to Copy always for this to work with Azure




回答3:


This is a guess...

But I think that perhaps the Azure IIS instance does not include PDF as a known MIME type.

To adjust for this try adding the mime type to your app's web.config file: http://blogs.iis.net/bills/archive/2008/03/25/how-to-add-mime-types-with-iis7-web-config.aspx

If this still doesn't work, then maybe consider:

  • changing the file extension
  • moving the PDF to Blob storage - in theory it should be more efficient to serve this static content direct from Blob storage
  • adding a dynamic proxy to your app for this file (not ideal!)


来源:https://stackoverflow.com/questions/5076846/url-content-on-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!