Exemplo n.º 1
0
        public static string siteData_SetContentType_For_File(this string fullPath, HttpResponseBase response)
        {
            var extension  = fullPath.extension();

            if (extension.valid() && response.notNull())
            {
                switch (extension)
                {
                    case ".js"  : response.ContentType = "application/javascript";  break;
                    case ".aspx": response.ContentType = "text/html"             ;  break;
                    case ".rz"  : response.ContentType = "text/html"             ;  break;    // for Razor pages
                    case ".html": response.ContentType = "text/html"             ;  break;
                    case ".htm" : response.ContentType = "text/html"             ;  break;
                    case ".jpg" : response.ContentType = "image/jpeg"            ;  break;
                    case ".jpeg": response.ContentType = "image/jpeg"            ;  break;
                    case ".gif" : response.ContentType = "image/gif"             ;  break;
                    case ".png" : response.ContentType = "image/png"             ;  break;
                    case ".css" : response.ContentType = "text/css"              ;  break;
                    case ".xml" : response.ContentType = "application/xml"       ;  break;
                    case ".xslt": response.ContentType = "application/xslt+xml"  ;  break;
                    default    : response.ContentType  = "text/plain"            ;  break;    // will also capture .txt
                }
            }
            return fullPath;
        }