首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >exe文件的下载链接导致“找不到”错误

exe文件的下载链接导致“找不到”错误
EN

Stack Overflow用户
提问于 2019-03-24 23:20:46
回答 1查看 470关注 0票数 1

我有一个ASP.NET核心剃刀页面应用程序,并想添加一个链接,当点击下载exe文件。因此,我将以下代码添加到我的Startup类中。

Startup.cs

代码语言:javascript
复制
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "folder1")),
    RequestPath = "/folder1"
});
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Add(".exe", "application/octect-stream");
app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = provider
});

剃刀视图

代码语言:javascript
复制
<a id="installButton" href="https://mysite.net.au/folder1/install/setup.exe">Install</a>

当我点击链接时,我得到下面的错误。

状态代码: 404;未找到

我还尝试使用application/vnd.microsoft.portable-executable作为MIME类型,但得到了相同的错误。

更新#1:我知道这个问题已经发布了--我在发布之前做了大量的搜索和阅读,但没有一个建议的解决方案解决了这个问题。因此,我需要发布我的确切代码/情况。

更新#2没有按钮来回答我的问题,所以我就在这里提供它:我能让它工作的唯一方法是添加两个静态文件选项。以下是工作的代码:

代码语言:javascript
复制
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Add(".exe", "application/octect-stream");
app.UseStaticFiles(new StaticFileOptions
{
   FileProvider = new physicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "folder1")),
   RequestPath = "/folder1",
   ServeUnknownFileTypes = true,
   DefaultContentType = "plain/text",
   ContentTypeProvider = provider
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-24 23:50:11

我测试了你的代码,发现了问题所在。您必须将最后两个UseStaticFiles声明合并为一个。

代码语言:javascript
复制
app.UseStaticFiles();
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Add(".exe", "application/octect-stream");
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "static")),
    RequestPath = "/folder1",
    ContentTypeProvider = provider
});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55325296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档