ASP.NET Core - Download .exe returns 404 error

I have a MVC application for ASP.NET and in the wwwroot folder, I added another folder called "Shaun", and in this folder I dumped exe to try and download:

enter image description here

Now, if I go to: http: // localhost: PORT / Shaun / chromesetup.exe I get a 404 error. I tried to add a handler below, but that will not work.

 <add name="Client exe" path="*.exe" verb="*" modules="StaticFileModule" resourceType="File" />

Additional info: the reason why I need to do this is that I have a client application that connects to this website, this client application is packaged using ClickOnce and goes to the wwwroot of the website, it previously worked with using MVC (pre core) and still does, but not with the kernel.

How to fix it?

+6
2

, :

app.UseStaticFiles(new StaticFileOptions
{
    ServeUnknownFileTypes = true, //allow unkown file types also to be served
    DefaultContentType = "Whatver you want eg: plain/text" //content type to returned if fileType is not known.
}

StaticFileMiddleware, , .

FileExtensionContentTypeProvider , ContentType Http Response. exe .

, , Exe :

var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Add(".exe", "application/vnd.microsoft.portable-executable"); //file ext, ContentType
app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = provider
});
+10

, ( .exe - ), , Middleware . Microsoft.AspNetCore.StaticFiles , UseStaticFiles Startup.Configure:

public void Configure(IApplicationBuilder app)
{
    app.UseStaticFiles();
}
0

Source: https://habr.com/ru/post/1015785/


All Articles