下载文件扩展名未下载 [英] download file extension is not downloading
问题描述
string url = ResolveUrl(ConfigurationManager.AppSettings [ResourcesFilePath] + filename);
if(!RequiresRegistration ||!DownloadRegistrationHelper.GetIsRegistrationEnabled())
{
htmlBuilder.AppendLine(string.Format(@ {1} ,url,linkText));
}
以上代码呈现以下方式
用于测定蜂蜜中氯霉素的自动固相萃取(SPE)方法
但在某些机器上没有下载下载文件扩展名(无论是chrome还是fiefox)
文件扩展名应该出现在所有浏览器中,还有其他选择吗?请告知
如果你想强制下载文件,而不是在浏览器中打开,你有几个选择。
Chrome和Firefox的最新版本支持下载
属性 [ ^ ]:
htmlBuilder.AppendLine( string .Format( @ < span class =code-string>< a href ={0}download ={1}> {2}< / a>,网址,文件名, linkText));
如果这不起作用,那么你需要使用自定义<$ c $提供文件c> Content-Disposition 标题。 StackOverflow上的这个答案 [ ^ ]解释了如何在IIS中设置标题。
在某些情况下,IE会尝试有用,并决定打开文件。你可以通过两个额外的标题来避免这种情况:X-Content-Type-Options:nosniff
和X-Download-Options:noopen
string url = ResolveUrl(ConfigurationManager.AppSettings["ResourcesFilePath"] + filename);
if (!RequiresRegistration || !DownloadRegistrationHelper.GetIsRegistrationEnabled())
{
htmlBuilder.AppendLine(string.Format(@"{1}", url, linkText));
}
above code renders in following manner
An Automated Solid Phase Extraction (SPE) Method for the Determination of Chloramphenicol in Honey
but while download file extension is not downloading in some machines (both in chrome & fiefox)
file extension should come in all browsers, any alternatives ? pls advise
If you want to force a file to be downloaded, rather than opening in the browser, you have a couple of options.
Recent versions of both Chrome and Firefox support thedownload
attribute[^]:
htmlBuilder.AppendLine(string.Format(@"<a href=""{0}"" download=""{1}"">{2}</a>", url, filename, linkText));
If that doesn't work, then you'll need to serve the file with a customContent-Disposition
header. This answer on StackOverflow[^] explains how to set the header in IIS.
In some cases, IE tries to be "helpful", and decides to open the file anyway. You can avoid that with two additional headers:X-Content-Type-Options: nosniff
andX-Download-Options: noopen
.
这篇关于下载文件扩展名未下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!