示例#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);
        }
示例#2
0
        /// <summary>
        /// 获取ContentTypesSection
        /// </summary>
        /// <returns>ContentTypesSection</returns>
        /// <remarks>获取ContentTypesSection</remarks>
        public static ContentTypesSection GetContentTypesSection()
        {
            ContentTypesSection section = (ContentTypesSection)ConfigurationBroker.GetSection("lib.web/contentTypes");

            if (section == null)
            {
                section = new ContentTypesSection();
            }

            return(section);
        }
        /// <summary>
        /// 得到文档类型的配置
        /// </summary>
        /// <returns>文档类型的配置信息</returns>
        public static ContentTypesSection GetConfig()
        {
            ContentTypesSection settings = (ContentTypesSection)ConfigurationBroker.GetSection("contentTypes");

            if (settings == null)
            {
                settings = new ContentTypesSection();
            }

            return(settings);
        }
示例#4
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);
        }