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

前端 未结 4 2255
抹茶落季
抹茶落季 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:24

    This is part of a solution I use on a local intranet. Some of the variables you will have to collect yourself as I pull them from a database but you may pull them from somewhere else.

    The only extra but I've got in there is a function called getMimeType which connects to the database and pulls back the correct mine type based on file extension. This defaults to application/octet-stream if none is found.

    // Clear the response buffer incase there is anything already in it.
    Response.Clear();
    Response.Buffer = true;
    
    // Read the original file from disk
    FileStream myFileStream = new FileStream(sPath, FileMode.Open);
    long FileSize = myFileStream.Length;
    byte[] Buffer = new byte[(int)FileSize];
    myFileStream.Read(Buffer, 0, (int)FileSize);
    myFileStream.Close();
    
    // Tell the browse stuff about the file
    Response.AddHeader("Content-Length", FileSize.ToString());
    Response.AddHeader("Content-Disposition", "inline; filename=" + sFilename.Replace(" ","_"));
    Response.ContentType = getMimeType(sExtention, oConnection);
    
    // Send the data to the browser
    Response.BinaryWrite(Buffer);
    Response.End();
    

提交回复
热议问题