Last active
August 29, 2015 14:14
-
-
Save kpmrafeeq/7bb89645adebd644f2bc to your computer and use it in GitHub Desktop.
Form posting in DD4T, post for as normal url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DD4TFormRouteHandler : MvcRouteHandler | |
{ | |
protected override IHttpHandler GetHttpHandler(RequestContext requestContext) | |
{ | |
string encodedVal; | |
switch (requestContext.HttpContext.Request.RequestType) | |
{ | |
case "POST": | |
encodedVal = requestContext.HttpContext.Request.Form["tprt"]; | |
break; | |
case "GET": | |
encodedVal = requestContext.HttpContext.Request.QueryString["tprt"]; | |
break; | |
default: | |
return null; | |
} | |
if (!string.IsNullOrWhiteSpace(encodedVal)) | |
{ | |
string decryptedString; | |
decryptedString = encodedVal.DecryptWithMachineKey(); | |
var parsedQueryString = HttpUtility.ParseQueryString(decryptedString); | |
var decodedParts = new Dictionary<string, string>(); | |
foreach (var key in parsedQueryString.AllKeys) | |
{ | |
decodedParts[key] = parsedQueryString[key]; | |
} | |
if (decodedParts.Count == 3) | |
{ | |
string controllerName = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == "c").Value); | |
string actionName = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == "a").Value); | |
string areaName = HttpUtility.UrlDecode(decodedParts.Single(x => x.Key == "ar").Value); | |
requestContext.RouteData.Values["action"] = actionName; | |
requestContext.RouteData.Values["controller"] = controllerName; | |
requestContext.RouteData.Values["area"] = areaName; | |
} | |
} | |
return base.GetHttpHandler(requestContext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment