我想知道在将ASP / ASPX文件上传到IIS Web服务器时要设置的HTTP标头Content-Type:
吗?
对于PHP,它是application/x-php
,所以我的猜测是application/x-asp
,但是我找不到任何可以证实这一点的信息,例如检查了http://www.asptutorial.info/sscript/ContentType.html。
答案 0 :(得分:2)
在网络上有很多可用的方法:我以前也有我的,直到我发现this great GitHub project涵盖了其中的巨大数量:它还包括有效的确定性双向映射,所以您也可以使用其他方式(从给定的MIME类型检索扩展名)。
我认为该文件可以帮助您:
using System;
using System.Collections.Generic;
using System.Linq;
namespace MimeTypes
{
public static class MimeTypeMap
{
private static readonly Lazy<IDictionary<string, string>> _mappings = new Lazy<IDictionary<string, string>>(BuildMappings);
private static IDictionary<string, string> BuildMappings()
{
var mappings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
#region Big freaking list of mime types
{".323", "text/h323"},
{".3g2", "video/3gpp2"},
{".3gp", "video/3gpp"},
{".3gp2", "video/3gpp2"},
{".3gpp", "video/3gpp"},
.
.
.
.
{"video/x-dv", ".dv"},
{"video/x-la-asf", ".lsf"},
{"video/x-ms-asf", ".asf"},
{"x-world/x-vrml", ".xof"},
#endregion
};
var cache = mappings.ToList(); // need ToList() to avoid modifying while still enumerating
foreach (var mapping in cache)
{
if (!mappings.ContainsKey(mapping.Value))
{
mappings.Add(mapping.Value, mapping.Key);
}
}
return mappings;
}
public static string GetMimeType(string extension)
{
if (extension == null)
{
throw new ArgumentNullException("extension");
}
if (!extension.StartsWith("."))
{
extension = "." + extension;
}
string mime;
return _mappings.Value.TryGetValue(extension, out mime) ? mime : "application/octet-stream";
}
public static string GetExtension(string mimeType)
{
return GetExtension(mimeType, true);
}
public static string GetExtension(string mimeType, bool throwErrorIfNotFound)
{
if (mimeType == null)
{
throw new ArgumentNullException("mimeType");
}
if (mimeType.StartsWith("."))
{
throw new ArgumentException("Requested mime type is not valid: " + mimeType);
}
string extension;
if (_mappings.Value.TryGetValue(mimeType, out extension))
{
return extension;
}
if (throwErrorIfNotFound)
{
throw new ArgumentException("Requested mime type is not registered: " + mimeType);
}
else
{
return string.Empty;
}
}
}
}
答案 1 :(得分:1)
.aspx文件没有这样的MIME类型,如果内容是HTML,则应将其命名为text/html
,因为客户端的.aspx文件与普通HTML文件相同。
.asp的唯一MIME是text/asp
。