Hello Guys,
I'm new to kentico (just working with kentico 7 for 3 weeks now) and i have a question about implementing a custom HttpHandler.
What i have done so far: I've created a new class library and created a httphandler:
public class SpelenHandler : IHttpHandler { /// <summary> /// You will need to configure this handler in the web.config file of your /// web and register it with IIS before being able to use it. For more information /// see the following link: http://go.microsoft.com/?linkid=8101007 /// </summary> #region IHttpHandler Members public bool IsReusable { // Return false in case your Managed Handler cannot be reused for another request. // Usually this would be false in case you have some state information preserved per request. get { return true; } } public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; // prepare the user's ID try { int gameId = 0; int.TryParse(context.Request.QueryString["gameid"].ToString(), out gameId); // get the object from database according to the data class name and ID IDataClass gameObj = DataClassFactory.NewDataClass("Custom.Game", gameId); // acquire the user's name int TimesPlayed = Convert.ToInt32(gameObj.GetValue("TimesPlayed").ToString()); TimesPlayed = TimesPlayed + 1; // change the user's full name gameObj.SetValue("TimesPlayed", TimesPlayed); // update the database record gameObj.Update(); context.Response.Write(JsonConvert.SerializeObject(true)); } catch { context.Response.Write(JsonConvert.SerializeObject(false)); } } #endregion }
I registered that handler in IIS and adjusted the web.config of my kentico instance. Now i am able to send jquery ajax requests to my handler and update my documenttype. This works perfectly! But a big disadvantage is compiling it against different versions of kentico (because of the reference to CMS.DataEngine.dll etc).
So therefor:
Is it possible to define this httphandler inside the app_code of kentico?
And what other options do i have for sending/recieving json ajax requests to/from the "backend"? I played already a bit with the service.asmx but i don't like that to much because it depends on the AjaxControlToolkit.
Kind regards, Alfred
Hi,
Best regards, Juraj Ondrus
Please, sign in to be able to submit a new answer.