/// <summary> /// 根据ContentTypeKey,得到Response的ContentType /// </summary> /// <param name="key">ContentTypeKey</param> /// <returns>ContentType</returns> /// <remarks>根据ContentTypeKey,得到Response的ContentType</remarks> public static string GetContentTypeByKey(string key) { ContentTypesSection section = ConfigSectionFactory.GetContentTypesSection(); key = key.ToLower(); ContentTypeConfigElement elt = section.ContentTypes[key]; string contentType = elt != null ? elt.ContentType : string.Empty; return(contentType); }
/// <summary> /// 根据文件扩展名,得到Response的ContentType /// </summary> /// <param name="fileExtesionName">文件扩展名</param> /// <returns>ContentType</returns> /// <remarks>根据文件扩展名,得到Response的ContentType</remarks> public static string GetContentTypeByFileExtesionName(string fileExtesionName) { ContentTypesSection section = ConfigSectionFactory.GetContentTypesSection(); foreach (ContentTypeConfigElement elt in section.ContentTypes) { if (StringInCollection(fileExtesionName, elt.FileExtensionNames, true)) { return(elt.ContentType); } } return(string.Empty); }