Asked by:
Generic Handlers

Question
-
Hello everyone!
I have multiple pages on my web application, and on most of them i have a plugin that call a ASHX handler to populate data on a paginated table. I create 1 ashx for each page, but the code is pretty much the same, like this:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpRequest Request = context.Request; HttpResponse Response = context.Response; Int32 intPage, intPageSize; Int32.TryParse(Convert.ToString(Request.Form["current"]), out intPage); Int32.TryParse(Convert.ToString(Request.Form["rowCount"]), out intPageSize); String searchPhrase = Convert.ToString(Request.Form["searchPhrase"]); String myAction = Convert.ToString(Request.Form["acc"]); String idRows = Convert.ToString(Request.Form["idRows"]); switch (myAction) { case "lista": Response.Write(LoadList()); break; case "delete": Delete(Convert.ToInt32(idRows)); Response.Write("OK - Excluded: " + idRows); break; case "deletelist": String[] ids = HttpUtility.UrlDecode(idRows).Replace("&", "").Replace("id[]=", "#").Split('#'); DeleteList(ids.ToList()); Response.Write("OK - List Excluded: " + String.Join(",", ids)); break; } }
This handler is responsible to Load, Delete and DeleteList where Load always return a list to my web page.
My question is, im creating a big project right now, since most of pages use 1 handler, i have a lot of handlers doing the same thing. It's possible to create a generic ashx so every page will post to same ashx?
Thankz!
Kind regards.
If you get your question answered, please come back and
Mark As Answer.
Web Developer- Moved by CoolDadTx Wednesday, January 27, 2016 4:28 PM ASP.NET related
Wednesday, January 27, 2016 3:59 PM
All replies
-
"ASHX handler"??
What kind of ASP.NET project is it? What .NET version?
Wednesday, January 27, 2016 4:03 PM -
Please post questions related to ASP.NET in the ASP.NET forums (http://forums.asp.net ).Wednesday, January 27, 2016 4:28 PM
-
Please post questions related to ASP.NET in the ASP.NET forums (http://forums.asp.net ).
I still don't think it's ASP.NET related. Sinc my doubt is in how to make my code generic in a way to every post accept the same code.If you get your question answered, please come back and
Mark As Answer.
Web DeveloperWednesday, January 27, 2016 5:13 PM -
"ASHX handler"??
What kind of ASP.NET project is it? What .NET version?
If you get your question answered, please come back and
Mark As Answer.
Web DeveloperWednesday, January 27, 2016 5:14 PM -
Hello everyone!
I have multiple pages on my web application, and on most of them i have a plugin that call a ASHX handler to populate data on a paginated table. I create 1 ashx for each page, but the code is pretty much the same, like this:
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; HttpRequest Request = context.Request; HttpResponse Response = context.Response; Int32 intPage, intPageSize; Int32.TryParse(Convert.ToString(Request.Form["current"]), out intPage); Int32.TryParse(Convert.ToString(Request.Form["rowCount"]), out intPageSize); String searchPhrase = Convert.ToString(Request.Form["searchPhrase"]); String myAction = Convert.ToString(Request.Form["acc"]); String idRows = Convert.ToString(Request.Form["idRows"]); switch (myAction) { case "lista": Response.Write(LoadList()); break; case "delete": Delete(Convert.ToInt32(idRows)); Response.Write("OK - Excluded: " + idRows); break; case "deletelist": String[] ids = HttpUtility.UrlDecode(idRows).Replace("&", "").Replace("id[]=", "#").Split('#'); DeleteList(ids.ToList()); Response.Write("OK - List Excluded: " + String.Join(",", ids)); break; } }
This handler is responsible to Load, Delete and DeleteList where Load always return a list to my web page.
My question is, im creating a big project right now, since most of pages use 1 handler, i have a lot of handlers doing the same thing. It's possible to create a generic ashx so every page will post to same ashx?
Thankz!
Kind regards.
If you get your question answered, please come back and
Mark As Answer.
Web DeveloperIf you get your question answered, please come back and
Mark As Answer.
Web DeveloperWednesday, January 27, 2016 7:48 PM -
Hello,
As it is, this really belongs in the asp.net forums.
They even have a C# specific forum:
http://forums.asp.net/37.aspx/1?C+
As Microsoft's ASP.Net forums are on a different platform, we cannot move the question for you.Karl
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
My Blog: Unlock PowerShell
My Book: Windows PowerShell 2.0 Bible
My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})Wednesday, January 27, 2016 11:31 PM