简体   繁体   English

控制器重定向到“ file.myextention”将返回“ file.zip”(C#MVC4)

[英]Controller redirect to “file.myextention” returns “file.zip” (C# MVC4)

I created a new file extention for a custom client application. 我为自定义客户端应用程序创建了新的文件扩展名。 The file is actually a zip file with some key files in them, I just renamed it to ".myextention". 该文件实际上是一个zip文件,其中包含一些密钥文件,我只是将其重命名为“ .myextention”。 (like Word and the DOCX extention) (如Word和DOCX扩展)

The file is generated on a website, where I have problems downloading the file. 该文件是在网站上生成的,我在下载该文件时遇到问题。

I create the zipfile directly in the "~/Content/" folder, so the client can download it directly and I can re-use the created files. 我直接在“〜/ Content /”文件夹中创建zip文件,因此客户端可以直接下载该文件,并且可以重复使用创建的文件。 Once created, I redirect the client to this file so their browser automaticly starts downloading the file. 创建完成后,我将客户端重定向到该文件,以便其浏览器自动开始下载文件。

This all works fine, but what the browser is downloading is a ".zip" file, instat of the ".myextention" file. 一切正常,但浏览器正在下载的是“ .zip”文件,即“ .myextention”文件的instat。

If I then look with the file-explorer inside the "~/Content/" folder, I find the file in the proper extention and all looks fine. 然后,如果我查看“〜/ Content /”文件夹中的文件浏览器,则会找到适当扩展名的文件,并且一切正常。

So some how IIS is renaming my "file.myextention" file to "file.zip". 因此,IIS如何将我的“ file.myextension”文件重命名为“ file.zip”。

在此输入图像描述

Add to web.config: 添加到web.config:

<staticContent>
  <mimeMap fileExtension=".myextention" mimeType="application/octet-stream" />
</staticContent>

Did the job... 做完了...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM