public static MvcHtmlString ActionLink(this HtmlHelper helper, string LinkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool generateToken) { RequestContext rc = helper.ViewContext.RequestContext; RouteCollection rtCollection = helper.RouteCollection; if (generateToken == true) { string token = TokenUtility.generateUrlToken(controllerName, actionName, routeValues, tokenPassword); routeValues.Add("urltoken", token); } string link = HtmlHelper.GenerateLink(rc, rtCollection, LinkText, null, actionName, controllerName, protocol, hostName, fragment, routeValues, htmlAttributes); MvcHtmlString mString = MvcHtmlString.Create(link); return(mString); }
public static MvcHtmlString ActionLink(this HtmlHelper helper, string LinkText, string actionName, string controllerName, bool generateToken) { RequestContext rc = helper.ViewContext.RequestContext; RouteCollection rtCollection = helper.RouteCollection; RouteValueDictionary rvd = new RouteValueDictionary(); if (generateToken == true) { string token = TokenUtility.generateUrlToken(controllerName, actionName, rvd, tokenPassword); rvd.Add("urltoken", token); } string link = HtmlHelper.GenerateLink(rc, rtCollection, LinkText, null, actionName, controllerName, rvd, null); MvcHtmlString mString = MvcHtmlString.Create(link); return(mString); }
//This is the extended method of Html.ActionLink.This class has the extended methods for the 10 overloads of this method //All the overloaded method applys the same logic excepts the parameters passed in public static MvcHtmlString ActionLink(this HtmlHelper helper, string LinkText, string actionName, bool generateToken) { RequestContext rc = helper.ViewContext.RequestContext; RouteCollection rtCollection = helper.RouteCollection; RouteValueDictionary rvd = new RouteValueDictionary(); if (generateToken == true) { //Call the generateUrlToken method which create the hash string token = TokenUtility.generateUrlToken("", actionName, rvd, tokenPassword); //The hash is added to the route value dictionary rvd.Add("urltoken", token); } //the link is formed by using the GenerateLink method. string link = HtmlHelper.GenerateLink(rc, rtCollection, LinkText, null, actionName, null, rvd, null); MvcHtmlString mString = MvcHtmlString.Create(link); return(mString); }
public static MvcHtmlString ActionLink(this HtmlHelper helper, string LinkText, string actionName, object routeValues, object htmlAttributes, bool generateToken) { RequestContext rc = helper.ViewContext.RequestContext; RouteCollection rtCollection = helper.RouteCollection; RouteValueDictionary rvd = new RouteValueDictionary(routeValues); if (generateToken == true) { string token = TokenUtility.generateUrlToken("", actionName, rvd, tokenPassword); rvd.Add("urltoken", token); } IDictionary <string, object> attrib; attrib = getDictionaryFromObject(htmlAttributes); //attrib.Add("attributes", htmlAttributes); string link = HtmlHelper.GenerateLink(rc, rtCollection, LinkText, null, actionName, null, rvd, attrib); MvcHtmlString mString = MvcHtmlString.Create(link); return(mString); }
public override void OnAuthorization(AuthorizationContext filterContext) { // basic athorization check base.OnAuthorization(filterContext); if (filterContext.HttpContext != null) { //Http referrer check and do the redirection if error occurs //It uses a controller named ErrorViewController and action named DisplayHttpReferrerError //These controller and action need to be present in your project in the project name space if (filterContext.HttpContext.Request.UrlReferrer == null) { filterContext.Result = new RedirectToRouteResult( new System.Web.Routing.RouteValueDictionary { { "langCode", filterContext.RouteData.Values["langCode"] }, { "controller", "ErrorView" }, { "action", "DisplayHttpReferrerError" }, { "ReturnUrl", filterContext.HttpContext.Request.RawUrl }, }); } } /*Add code here to check the domain name the request come from*/ // The call for validation of URL hash and do the redirection if error occurs //It uses a controller named ErrorViewController and action named DisplayURLError //These controller and action need to be present in your project in the project name space if (TokenUtility.validateToken(filterContext.RequestContext.RouteData.Values, ActionLinkExtensions.tokenPassword) == false) { filterContext.Result = new RedirectToRouteResult( new System.Web.Routing.RouteValueDictionary { { "langCode", filterContext.RouteData.Values["langCode"] }, { "controller", "ErrorView" }, { "action", "DisplayURLError" }, { "ReturnUrl", filterContext.HttpContext.Request.RawUrl } }); } }