I want to create an Ihttphandler that controls user whether the user is one of the members of my web site when the user request a downloadble files such as .zip or .rar. I have written and given it below my codes dont work. When files are requested, Ihttphandler
checks user but it doesnt let the user download the file. Anyone solve the problem please?
I solved the problem. It occurs because it writes the content of file to the output stream as html format but because this is a downloable file, the httphandler must write the content of file the output stream as zip or .mp3 whatever the file
type is.
Now, I can check the requests coming for my files not only aspx files.
None
0 Points
4 Posts
IHttphandler for checking downloadable files such as .zip
Mar 19, 2006 04:02 PM|ghostofpc|LINK
hi everyone
I have a problem with Ihttphandler.
I want to create an Ihttphandler that controls user whether the user is one of the members of my web site when the user request a downloadble files such as .zip or .rar. I have written and given it below my codes dont work. When files are requested, Ihttphandler checks user but it doesnt let the user download the file. Anyone solve the problem please?
public class handler : IHttpHandler{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
string[] parts = context.Request.Url.Segments;
string last = parts[parts.Length - 1];
if (context.User.Identity.IsAuthenticated)
{
context.Response.WriteFile("files/" + last);
}
else
{
context.Response.Redirect("nopermission.html");
}
}
}
Member
10 Points
5 Posts
Re: IHttphandler for checking downloadable files such as .zip
Mar 19, 2006 04:21 PM|kobipinhasov|LINK
Try this
context.Response.WriteFile(context.Server.MapPath("files/" + last));
None
0 Points
4 Posts
Re: IHttphandler for checking downloadable files such as .zip
Mar 20, 2006 01:40 PM|ghostofpc|LINK
thanks for reply Kobipinhasov
context.Response.ContentType = "audio/mpeg"
context.Response.WriteFile("/myhandler/files/" + last);
I solved the problem. It occurs because it writes the content of file to the output stream as html format but because this is a downloable file, the httphandler must write the content of file the output stream as zip or .mp3 whatever the file type is.
Now, I can check the requests coming for my files not only aspx files.