private void CanvasRedirect(string url) { string content = CanvasUrlBuilder.GetCanvasRedirectHtml(url); Response.ContentType = "text/html"; Response.Write(content); }
public HttpUrlThen() { _canvasUrlBuilder = new CanvasUrlBuilder( CanvasUrlBuilderHelper.GetFakeFacebookApplication(false), CanvasUrlBuilderHelper.GetFakeHttpRequest( new Uri("http://localhost:16151/CSASPNETFacebookApp/default.aspx"), null)); }
public static string GenerateCanvasUrl(UrlHelper urlHelper, string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) { string url = UrlHelper.GenerateUrl(routeName, actionName, controllerName, routeValues, routeCollection, requestContext, includeImplicitMvcValues); CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, urlHelper.RequestContext.HttpContext.Request); return(urlBuilder.BuildCanvasPageUrl(url).ToString()); }
public AndHttpsUrlAndReferUrlAsAppBetaFacebookThen() { _canvasUrlBuilder = new CanvasUrlBuilder( CanvasUrlBuilderHelper.GetFakeFacebookApplication(false), CanvasUrlBuilderHelper.GetFakeHttpRequest( new Uri("https://localhost:16151/CSASPNETFacebookApp/default.aspx"), new Uri("https://apps.beta.facebook.com/app/default.aspx"))); }
/// <summary> /// Enables processing of the result of an action method by a custom type that inherits from the <see cref="T:System.Web.Mvc.ActionResult"/> class. /// </summary> /// <param name="context">The context within which the result is executed.</param> /// <exception cref="T:System.ArgumentNullException">The <paramref name="context"/> parameter is null.</exception> public override void ExecuteResult(ControllerContext context) { var content = CanvasUrlBuilder.GetCanvasRedirectHtml(new Uri(Url)); context.Controller.TempData.Keep(); context.HttpContext.Response.ContentType = "text/html"; context.HttpContext.Response.Write(content); }
public GivenHttp_NoBeta_NoDefaultCancelUrlPathThen() { _canvasUrlBuilder = new CanvasUrlBuilder( new DefaultFacebookApplication { CanvasUrl = "http://localhost:16151/CSASPNETFacebookApp/", CanvasPage = "http://apps.facebook.com/csharpsamplestwo/" }, GetHttpRequest()); }
public static string GenerateCanvasUrl(UrlHelper urlHelper, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) { Contract.Requires(urlHelper != null && urlHelper.RequestContext != null && urlHelper.RequestContext.HttpContext != null && urlHelper.RequestContext.HttpContext.Request != null && urlHelper.RequestContext.HttpContext.Request.Url != null && urlHelper.RequestContext.HttpContext.Request.Headers != null && urlHelper.RouteCollection != null); string url = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues); CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, requestContext.HttpContext.Request); return(urlBuilder.BuildCanvasPageUrl(url).ToString()); }
protected internal override Uri GetLoginUrl(IFacebookApplication settings, HttpContextBase httpContext, IDictionary <string, object> parameters) { var authorizer = new CanvasAuthorizer(settings, httpContext) { ReturnUrlPath = ReturnUrlPath, CancelUrlPath = CancelUrlPath, LoginDisplayMode = LoginDisplayMode }; if (!String.IsNullOrEmpty(Permissions)) { authorizer.Permissions = Permissions.Replace(" ", String.Empty).Split(','); } if (string.IsNullOrEmpty(CancelUrlPath)) { // set it to this same url instead of going to facebook.com var canvasUrlBuilder = new CanvasUrlBuilder(settings, httpContext.Request); var currentPathAndQuery = canvasUrlBuilder.CurrentCanvasPathAndQuery; if (currentPathAndQuery.Contains("?")) { var parts = currentPathAndQuery.Split('?'); if (parts.Length == 2 && !string.IsNullOrEmpty(parts[1])) { var queryStrings = FacebookUtils.ParseUrlQueryString(parts[1]); // remove oauth 2 error querystrings. // error_reason=user_denied&error_denied=access_denied&error_description=The+user+denied+your+request. if (queryStrings.ContainsKey("error_reason")) { queryStrings.Remove("error_reason"); } if (queryStrings.ContainsKey("error_denied")) { queryStrings.Remove("error_denied"); } if (queryStrings.ContainsKey("error_description")) { queryStrings.Remove("error_description"); } currentPathAndQuery = parts[0] + "?" + FacebookUtils.ToJsonQueryString(queryStrings); } } authorizer.CancelUrlPath = currentPathAndQuery; } return(authorizer.GetLoginUrl(null)); }
private string GeneratePageLink(string linkText, int pageNumber) { var routeDataValues = viewContext.RequestContext.RouteData.Values; RouteValueDictionary pageLinkValueDictionary; // Avoid canonical errors when page count is equal to 1. if (pageNumber == 1) { pageLinkValueDictionary = new RouteValueDictionary(this.linkWithoutPageValuesDictionary); if (routeDataValues.ContainsKey("page")) { routeDataValues.Remove("page"); } } else { pageLinkValueDictionary = new RouteValueDictionary(this.linkWithoutPageValuesDictionary) { { "page", pageNumber } }; } // To be sure we get the right route, ensure the controller and action are specified. if (!pageLinkValueDictionary.ContainsKey("controller") && routeDataValues.ContainsKey("controller")) { pageLinkValueDictionary.Add("controller", routeDataValues["controller"]); } if (!pageLinkValueDictionary.ContainsKey("action") && routeDataValues.ContainsKey("action")) { pageLinkValueDictionary.Add("action", routeDataValues["action"]); } // 'Render' virtual path. var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(viewContext.RequestContext, pageLinkValueDictionary); if (virtualPathForArea == null) { return(null); } CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(); var fullUrl = urlBuilder.BuildCanvasPageUrl(virtualPathForArea.VirtualPath).ToString(); var stringBuilder = new StringBuilder("<a target='_top'"); stringBuilder.AppendFormat(" href=\"{0}\">{1}</a>", fullUrl, linkText); var url = stringBuilder.ToString(); return(url); }
public override void ExecuteResult(ControllerContext context) { string destinationPathAndQuery = UrlHelper.GenerateUrl(RouteName, null /* actionName */, null /* controllerName */, RouteValues, RouteTable.Routes, context.RequestContext, false /* includeImplicitMvcValues */); var canvasUrlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, context.HttpContext.Request); var canvasUrl = canvasUrlBuilder.BuildCanvasPageUrl(destinationPathAndQuery); var content = CanvasUrlBuilder.GetCanvasRedirectHtml(canvasUrl); context.Controller.TempData.Keep(); context.HttpContext.Response.ContentType = "text/html"; context.HttpContext.Response.Write(content); }
/// <summary> /// Generates the link. /// </summary> /// <param name="requestContext">The request context.</param> /// <param name="routeCollection">The route collection.</param> /// <param name="linkText">The link text.</param> /// <param name="routeName">Name of the route.</param> /// <param name="actionName">Name of the action.</param> /// <param name="controllerName">Name of the controller.</param> /// <param name="protocol">The protocol.</param> /// <param name="hostName">Name of the host.</param> /// <param name="fragment">The fragment.</param> /// <param name="routeValues">The route values.</param> /// <param name="htmlAttributes">The HTML attributes.</param> /// <param name="includeImplicitMvcValues">if set to <c>true</c> [include implicit MVC values].</param> /// <returns></returns> private static string GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool includeImplicitMvcValues) { htmlAttributes = htmlAttributes ?? new Dictionary <string, object>(); htmlAttributes["target"] = "_top"; string webUrl = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues); var applicationPath = requestContext.HttpContext.Request.ApplicationPath; if (!string.IsNullOrEmpty(applicationPath) && applicationPath != "/" && webUrl.StartsWith(applicationPath)) { webUrl = webUrl.Substring(applicationPath.Length); } CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, requestContext.HttpContext.Request); string url = urlBuilder.BuildCanvasPageUrl(webUrl).ToString(); var tagBuilder = new TagBuilder("a") { InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty }; tagBuilder.MergeAttributes(htmlAttributes); tagBuilder.MergeAttribute("href", url); return(tagBuilder.ToString(TagRenderMode.Normal)); }
public static string GenerateCanvasUrl(UrlHelper urlHelper, string routeName, string actionName, string controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, bool includeImplicitMvcValues) { Contract.Requires(urlHelper != null && urlHelper.RequestContext != null && urlHelper.RequestContext.HttpContext != null && urlHelper.RequestContext.HttpContext.Request != null && urlHelper.RequestContext.HttpContext.Request.Url != null && urlHelper.RequestContext.HttpContext.Request.Headers != null && urlHelper.RouteCollection != null); string url = UrlHelper.GenerateUrl(routeName, actionName, controllerName, routeValues, routeCollection, requestContext, includeImplicitMvcValues); CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, urlHelper.RequestContext.HttpContext.Request); return urlBuilder.BuildCanvasPageUrl(url).ToString(); }
/// <summary> /// Generates the link. /// </summary> /// <param name="requestContext">The request context.</param> /// <param name="routeCollection">The route collection.</param> /// <param name="linkText">The link text.</param> /// <param name="routeName">Name of the route.</param> /// <param name="actionName">Name of the action.</param> /// <param name="controllerName">Name of the controller.</param> /// <param name="protocol">The protocol.</param> /// <param name="hostName">Name of the host.</param> /// <param name="fragment">The fragment.</param> /// <param name="routeValues">The route values.</param> /// <param name="htmlAttributes">The HTML attributes.</param> /// <param name="includeImplicitMvcValues">if set to <c>true</c> [include implicit MVC values].</param> /// <returns></returns> private static string GenerateLinkInternal(RequestContext requestContext, RouteCollection routeCollection, string linkText, string routeName, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes, bool includeImplicitMvcValues) { htmlAttributes = htmlAttributes ?? new Dictionary<string, object>(); htmlAttributes["target"] = "_top"; string webUrl = UrlHelper.GenerateUrl(routeName, actionName, controllerName, protocol, hostName, fragment, routeValues, routeCollection, requestContext, includeImplicitMvcValues); var applicationPath = requestContext.HttpContext.Request.ApplicationPath; if (!string.IsNullOrEmpty(applicationPath) && applicationPath != "/" && webUrl.StartsWith(applicationPath)) { webUrl = webUrl.Substring(applicationPath.Length); } CanvasUrlBuilder urlBuilder = new CanvasUrlBuilder(FacebookApplication.Current, requestContext.HttpContext.Request); string url = urlBuilder.BuildCanvasPageUrl(webUrl).ToString(); var tagBuilder = new TagBuilder("a") { InnerHtml = (!String.IsNullOrEmpty(linkText)) ? HttpUtility.HtmlEncode(linkText) : String.Empty }; tagBuilder.MergeAttributes(htmlAttributes); tagBuilder.MergeAttribute("href", url); return tagBuilder.ToString(TagRenderMode.Normal); }