I have a class name FileCreator that create a file and return the path ,
After this class create the file and return the path , I sent the path to a generic handler name FileDownloader (ashx file) via querystring
And he is responsible for downloading the file.
The problem is that the path may contains characters like &,+,... and they causes some problems in the querystring .
I thought about creating a session in the FileCreator , and give him a guid as a name , this guid will be send in the querystring for the FileDownlaoder
and he will read the path from the session and delete the session after it.
Is this a good way to solve this problem ? is there a better solution?
You can pass the path to ashx handler via Session.
ashx file:
public class Handler : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext ctx)
{
//get the path from Session
ctx.Response.Write(ctx.Session["key"]);
}
}
Please mark the replies as answers if they help or unmark if not.
Feedback to us
talhumy
Member
1 Points
6 Posts
Best way to send data from class to generic handler
Aug 19, 2012 09:42 AM|LINK
Hello,
I have a class name FileCreator that create a file and return the path ,
After this class create the file and return the path , I sent the path to a generic handler name FileDownloader (ashx file) via querystring
And he is responsible for downloading the file.
The problem is that the path may contains characters like &,+,... and they causes some problems in the querystring .
I thought about creating a session in the FileCreator , and give him a guid as a name , this guid will be send in the querystring for the FileDownlaoder
and he will read the path from the session and delete the session after it.
Is this a good way to solve this problem ? is there a better solution?
mitja.GTI
Star
11157 Points
2094 Posts
Re: Best way to send data from class to generic handler
Aug 19, 2012 12:51 PM|LINK
You can use HttpServerUtility.UrlEncode Method (String) to encode the string/filename.
mitja.gti | www.mitjagti.com
oned_gk
All-Star
31715 Points
6480 Posts
Re: Best way to send data from class to generic handler
Aug 19, 2012 07:39 PM|LINK
in FileCreator
Try using server path \folder\file.ext and replace "\" with "/"
or
replace the character that causing &,+,... a when creating file.
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: Best way to send data from class to generic handler
Aug 23, 2012 06:09 AM|LINK
You can pass the path to ashx handler via Session.
ashx file:
public class Handler : IHttpHandler, System.Web.SessionState.IReadOnlySessionState { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext ctx) { //get the path from Session ctx.Response.Write(ctx.Session["key"]); } }Feedback to us
Develop and promote your apps in Windows Store