Skip to content

Instantly share code, notes, and snippets.

@kpmrafeeq
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpmrafeeq/7bb89645adebd644f2bc to your computer and use it in GitHub Desktop.
Save kpmrafeeq/7bb89645adebd644f2bc to your computer and use it in GitHub Desktop.
Form posting in DD4T, post for as normal url
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