Exemplo 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 = ConfigSectionFactory.GetContentTypesSection();

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

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

            return(contentType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据文件名得到文件的配置信息
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public ContentTypeConfigElement FindElementByFileName(string fileName)
        {
            ContentTypeConfigElement result = null;

            string fileExt = Path.GetExtension(fileName);

            if (string.IsNullOrEmpty(fileExt) == false)
            {
                fileExt = fileExt.Trim('.').ToLower();                //Modify 20071010, 大小写问题

                foreach (ContentTypeConfigElement element in this)
                {
                    if (element.FileExtensionNames.Contains(fileExt))
                    {
                        result = element;
                        break;
                    }
                }
            }

            return(result);
        }