|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace CustomHttpHandlers
{
public class ClickOnceApplicationHandler : IHttpHandler
{
public ClickOnceApplicationHandler()
{
}
#region IHttpHandler Members
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
Logger.Log("IHttpHandler.ProcessRequest started for " + context.Request.Path);
context.Response.Cache.SetExpires(DateTime.Now);
context.Response.Cache.SetValidUntilExpires(true);
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
string path = context.Server.MapPath(context.Request.Path).ToLower();
if (File.Exists(path))
{
//Ensure browser handles application files correctly
if (path.EndsWith(".application"))
context.Response.ContentType = "application/x-ms-application";
byte[] outputBinaryArray;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader r = new BinaryReader(fs);
outputBinaryArray = r.ReadBytes(Convert.ToInt32(fs.Length));
r.Close();
fs.Close();
context.Response.BinaryWrite(outputBinaryArray);
}
else
{
throw new HttpException(404, "File not found");
}
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.