Ejemplo n.º 1
0
        /// <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 = WebConfigFactory.GetContentTypesSection();

            key = key.ToLower();
            ContentTypeConfigElement elt = section.ContentTypes[key];

            string contentType = elt != null ? elt.ContentType : string.Empty;

            return(contentType);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据文件扩展名,得到Response的ContentType
        /// </summary>
        /// <param name="fileExtesionName">文件扩展名</param>
        /// <returns>ContentType</returns>
        /// <remarks>根据文件扩展名,得到Response的ContentType</remarks>
        public static string GetContentTypeByFileExtesionName(string fileExtesionName)
        {
            ContentTypesSection section = WebConfigFactory.GetContentTypesSection();

            foreach (ContentTypeConfigElement elt in section.ContentTypes)
            {
                if (StringInCollection(fileExtesionName, elt.FileExtensionNames, true))
                {
                    return(elt.ContentType);
                }
            }

            return(string.Empty);
        }