Displaying ad content from Respose.WriteFile()/ Response.ContentType

前端 未结 4 2245
抹茶落季
抹茶落季 2021-02-18 21:48

How would one display any add content from a \"dynamic\" aspx page? Currently I am working on using the System.Web.HttpResponse \"Page.Response\" to write a file that is stored

4条回答
  •  生来不讨喜
    2021-02-18 22:18

    This is ugly, but the best way is to look at the file and set the content type as appropriate:

    switch ( fileExtension )
    {
        case "pdf": Response.ContentType = "application/pdf"; break; 
        case "swf": Response.ContentType = "application/x-shockwave-flash"; break; 
    
        case "gif": Response.ContentType = "image/gif"; break; 
        case "jpeg": Response.ContentType = "image/jpg"; break; 
        case "jpg": Response.ContentType = "image/jpg"; break; 
        case "png": Response.ContentType = "image/png"; break; 
    
        case "mp4": Response.ContentType = "video/mp4"; break; 
        case "mpeg": Response.ContentType = "video/mpeg"; break; 
        case "mov": Response.ContentType = "video/quicktime"; break; 
        case "wmv":
        case "avi": Response.ContentType = "video/x-ms-wmv"; break; 
    
        //and so on          
    
        default: Response.ContentType = "application/octet-stream"; break; 
    }
    

提交回复
热议问题