private static XRpcStruct CreateBlogStruct( BlogPostPart blogPostPart, UrlHelper urlHelper) { var url = urlHelper.AbsoluteAction(() => urlHelper.ItemDisplayUrl(blogPostPart)); if (blogPostPart.HasDraft()) { url = urlHelper.AbsoluteAction("Preview", "Item", new { area = "Contents", id = blogPostPart.ContentItem.Id }); } var blogStruct = new XRpcStruct() .Set("postid", blogPostPart.Id) .Set("title", HttpUtility.HtmlEncode(blogPostPart.Title)) .Set("description", blogPostPart.Text) .Set("link", url) .Set("permaLink", url); blogStruct.Set("wp_slug", blogPostPart.As <IAliasAspect>().Path); if (blogPostPart.PublishedUtc != null) { blogStruct.Set("dateCreated", blogPostPart.PublishedUtc); blogStruct.Set("date_created_gmt", blogPostPart.PublishedUtc); } return(blogStruct); }
public void AbsoluteActionWithAction() { string expectedUrl = String.Format("http://localhost{0}/app/home/test", MvcHelper.AppPathModifier); string generatedUrl = _helper.AbsoluteAction("test"); Assert.AreEqual(expectedUrl, generatedUrl); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="navId"></param> /// <returns></returns> private static string GetSubNavigationItem(XElement node, string navId) { var subNavBuilder = new StringBuilder(); subNavBuilder.AppendLine("<ul class=\"nav navbar-nav collapse\" id=\"" + navId + "\">"); foreach (var subNav in node.GetSubNavbarXmlElements()) { var sitemapNode = new SiteMapNode(subNav); var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var url = urlHelper.AbsoluteAction(sitemapNode.Action, sitemapNode.Controller); // TODO: For later. This hardcode is ugly. if (url == "http://" + HttpContext.Current.Request.Url.Authority) { url = "#"; } subNavBuilder.AppendLine("<li><a href=\"" + url + "\"><span style=\"margin-right:5px;\" class=\"subnavbar-icon " + sitemapNode.CssClass + "\"></span>" + sitemapNode.Display + "</a></li>"); } subNavBuilder.AppendLine("</ul>"); return(subNavBuilder.ToString()); }
private void SendEmailToCustomer(Consultation consultation, Contact contact) { var template = Dictionary.ConsultationBookedThankYouEmail; var title = Dictionary.ThankyouForBookingConsultationEmailTitle; _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new { Title = title, contact.FirstName, Duration = consultation.DurationDescription, ImageUrl = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl), PrivacyPolicyLink = _urlHelper.AbsoluteAction("PrivacyPolicy", "Home"), UnsubscribeLink = _urlHelper.AbsoluteAction("Unsubscribe", "Account", new { code = contact.Name }), DateTime.Now.Year }), contact.EmailAddress, contact.FullName, _config.SupportEmailAddress, _config.CompanyName); }
public static DataTableModel DataTableModel <TController, T> ( this IHtmlHelper html, string id, Expression <Func <TController, DataTableActionResult <T> > > exp, params ColumnModel[] columns ) where T : class, new() { if (columns?.Any() != true) { columns = typeof(T).GetColumns(); } var methodInfo = exp.MethodInfo(); var controllerName = typeof(TController).Name; controllerName = controllerName.Substring(0, controllerName.LastIndexOf(nameof(Controller), StringComparison.CurrentCultureIgnoreCase)); var urlHelper = new UrlHelper(html.ViewContext); var ajaxUrl = urlHelper.AbsoluteAction(methodInfo.Name, controllerName); return(new DataTableModel(id, ajaxUrl, columns)); }
public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, Area area) { if (area == Area.Auto) { area = url.RequestContext.HttpContext.User.IsInRole(Models.RoleName.Admin) ? Area.Admin : Area.User; } return(url.AbsoluteAction(actionName, controllerName, new { area = area == Area.None ? null : area.ToString() })); }
private void SendEmailToNineStar(Donation donation) { var template = Dictionary.DonationReceivedEmail; var title = "We have received a donation!"; _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new { Title = title, donation.Customer, donation.CustomerEmail, Amount = donation.DonationAmount, donation.Currency, LinkToSummary = _urlHelper.AbsoluteAction("Index", "Donations"), Company = _config.CompanyName, ImageUrl = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl) }), _config.SupportEmailAddress, _config.CompanyName, _config.SupportEmailAddress, _config.CompanyName); }
private void SendEmailToCustomer(Contact contact) { var template = Dictionary.SupportQuery; var title = Dictionary.EmailThankYouTitle; if (contact != null && !contact.IsUnsubscribed) { _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new { Title = title, contact.FirstName, PrivacyPolicyLink = _urlHelper.AbsoluteAction("PrivacyPolicy", "Home"), UnsubscribeLink = _urlHelper.AbsoluteAction("Unsubscribe", "Account", new { code = contact.Name }), DateTime.Now.Year }), contact.EmailAddress, contact.FirstName, _config.SupportEmailAddress, _config.CompanyName); } }
public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, Area area, object routeValues) { if (area == Area.Auto) { area = url.RequestContext.HttpContext.User.IsInRole(Models.RoleName.Admin) ? Area.Admin : Area.User; } var values = App.MergeObjects(new { area = area == Area.None ? null : area.ToString() }, routeValues); return(url.AbsoluteAction(actionName, controllerName, (object)values)); }
protected LoginResponse AuthorizeCustomer(int customerID) { var response = new LoginResponse(); // Get the customer's identity var identity = GetIdentity(customerID); // Get the redirect URL (for silent logins) or create the forms ticket response.RedirectUrl = GetSilentLoginRedirect(identity); // Continue to authorize this customer if they signed in to the right site if (response.RedirectUrl.IsEmpty()) { CreateFormsAuthenticationTicket(identity); if (HttpContext.Current != null && HttpContext.Current.Request != null) { var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); response.LandingUrl = urlHelper.AbsoluteAction("Index", "Dashboard"); // subscription logic if (!identity.IsSubscribedMonthly) { response.LandingUrl = urlHelper.AbsoluteAction("ItemList", "Shopping"); } } else { response.LandingUrl = "/"; } } // Mark the response as successful response.Success(); return(response); }
/// <summary> /// Created for uses outside of the HttpContext like in UnitTest projects. /// </summary> /// <param name="urlHelper"></param> /// <param name="edition"></param> /// <param name="fragment"></param> /// <returns></returns> public string GetEditionUrl(UrlHelper urlHelper, EditionEntity edition, string fragment = null) { string url; switch (edition.Status) { case EditionStatusType.PreDraft: case EditionStatusType.Draft: case EditionStatusType.WaitingForApproval: case EditionStatusType.Approved: url = urlHelper.AbsoluteAction("Draft", "Edition", new { id = edition.EditionId, name = edition.EditionName.ToUrlString() }); break; default: url = urlHelper.AbsoluteAction("Edit", "Edition", new { id = edition.EditionId, name = edition.EditionName.ToUrlString() }); break; } return(url + fragment); }
public string CreateProtectedUrl(string action, CommentPart part) { var workContext = _orchardServices.WorkContext; if (workContext.HttpContext != null) { var url = new UrlHelper(workContext.HttpContext.Request.RequestContext); return(url.AbsoluteAction(action, "Comment", new { area = "Orchard.Comments", nonce = CreateNonce(part, TimeSpan.FromDays(7)) })); } return(null); }
private string CreateProtectedUrl(string action, BidPart part) { var workContext = _workContextAccessor.GetContext(); if (workContext.HttpContext != null) { var url = new UrlHelper(workContext.HttpContext.Request.RequestContext); return(url.AbsoluteAction(action, "Bid", new { area = "Devq.Bids", nonce = _bidService.CreateNonce(part, TimeSpan.FromDays(7)) })); } return(null); }
public void SendPromoCode(EmailPromoCodeViewModel model) { var template = Dictionary.PromoCodeEmail; var title = Dictionary.PromoCodeEmailTitle; var contact = _contactService.GetOrCreateContact("", model.Name, model.EmailAddress); _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new { Title = title, model.FirstName, model.EmailAddress, ImageUrl = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl), PrivacyPolicyLink = _urlHelper.AbsoluteAction("PrivacyPolicy", "Home"), UnsubscribeLink = _urlHelper.AbsoluteAction("Unsubscribe", "Account", new { code = contact.Name }), PromoLink = _urlHelper.AbsoluteAction("Register", "Account", new { promoCode = model.PromoCode.Code }), PromoDetails = model.PromoCode.Details, DateTime.Now.Year }), model.EmailAddress, model.Name, _config.SupportEmailAddress, _config.CompanyName); model.PromoCode.SentOn = DateTime.Now; _promoCodesRepository.Update(model.PromoCode); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <returns></returns> private static string GetNavbarHeader(XDocument node) { var sitemapNode = new SiteMapNode(node.GetHeaderXmlElement()); var headerStringBuilder = new StringBuilder(); var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var url = urlHelper.AbsoluteAction(sitemapNode.Action, sitemapNode.Controller); headerStringBuilder.AppendLine("<div class=\"navbar-header\" >"); headerStringBuilder.AppendLine("<a href=\"" + url + "\" data-toggle=\"collapse\" data-target=\"#" + sitemapNode.NavId + "\" class=\"navbar-brand\">" + sitemapNode.Display + "</a>"); headerStringBuilder.AppendLine("</div>"); return(headerStringBuilder.ToString()); }
public static MailMessage AddUnsubscribe(MailMessage message, string unsubscribeUserId) { UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext); var unsubscribeUrl = url.AbsoluteAction("Unsubscribe", "Account", new { userId = unsubscribeUserId }); message.Headers.Add("List-Unsubscribe", String.Format(CultureInfo.InvariantCulture, "<{0}>", unsubscribeUrl)); message.Body += $"<br/><br/>To Unsubscribe from further emails please click on this <a href=\"{unsubscribeUrl}\">Unsubscribe</a> link.<br/>"; return(message); }
public Uri CreateDetailLink(UrlHelper urlHelper, IItem item, bool absolute) { if (!s_typeToControllerMapping.ContainsKey(item.GetType())) { throw new ArgumentException(String.Format("No controller mapped to type {0}.", item.GetType())); } var controller = s_typeToControllerMapping[item.GetType()]; return(new Uri( absolute ? urlHelper.AbsoluteAction("Detail", controller, new { id = item.ID }) : urlHelper.Action("Detail", controller, new { id = item.ID }))); }
public static string DynamicAction( this UrlHelper url, string action, Type controller, object routeValues = null, bool absoluteUrl = false) { var route = CustomHelpers.AddAreaRouteValue(controller, routeValues); var controllerName = controller.GetControllerName(); return(absoluteUrl ? url.AbsoluteAction(action, controllerName, route) : url.Action(action, controllerName, route)); }
/// <summary> /// Generates a fully qualified URL to an action method by using /// the specified action name, controller name and route values. /// </summary> /// <param name="url">The URL helper.</param> /// <param name="actionName">The name of the action method.</param> /// <param name="controllerName">The name of the controller.</param> /// <param name="routeValues">The route values.</param> /// <returns>The absolute URL.</returns> public static String AbsoluteAction(String actionName, String controllerName, Object routeValues = null) { var context = System.Web.HttpContext.Current; if (context != null) { var request = context.Request; if (request != null) { var helper = new UrlHelper(request.RequestContext); return(helper.AbsoluteAction(actionName, controllerName, routeValues)); } } return(null); }
private string CreateDefaultRobotsContent() { const string template = @"# robots.txt generated at {0} User-agent: * Disallow: {1}"; var absoluteUrl = _orchardServices.WorkContext.CurrentSite.BaseUrl; var isSitemapEnabled = _featureManager.GetEnabledFeatures().Any(x => x.Id == "IDeliverable.Seo.Sitemap"); var sitemapEntry = isSitemapEnabled ? $"Sitemap: {_urlHelper.AbsoluteAction("Index", "Sitemap", new { Area = "IDeliverable.Seo" })}" : default(string); return(String.Format(template, absoluteUrl, sitemapEntry)); }
public MvcHtmlString GetPreviewUrl(UrlHelper helper) { var root = HttpContext.Current.Request.ApplicationPath ?? "/"; if (!root.EndsWith("/")) { root += "/"; } var path = string.Format("{0}{1}/{2}", root, SelectedMeme, string.Join("/", Lines)); var strippedPath = _previewUrlStripper.Replace(path, "-"); var trimmedPath = strippedPath.TrimEnd('/'); var pathWithExtension = trimmedPath + ".jpg"; return(MvcHtmlString.Create(helper.AbsoluteAction(pathWithExtension))); }
private void RequestEmailChange(UserModel viewModel, UrlHelper helper, User user) { string originalPendingEmail = user.PendingEmail; if (viewModel.PendingEmail != user.EmailAddress) { viewModel.CopyTo(user); string actionEndpoint = helper.AbsoluteAction("ConfirmEmail", "Account"); Uri confirmationEndpoint = new Uri(actionEndpoint); EmailConfirmationManager.Request(user, confirmationEndpoint); } else { viewModel.CopyTo(user); } }
public void Execute(Orchard.Core.Feeds.Models.FeedContext context) { var idValue = context.ValueProvider.GetValue("id"); var connectorValue = context.ValueProvider.GetValue("connector"); var limitValue = context.ValueProvider.GetValue("limit"); var limit = 20; if (limitValue != null) { limit = (int)limitValue.ConvertTo(typeof(int)); } var id = (int)idValue.ConvertTo(typeof(int)); var connectorName = (string)connectorValue.ConvertTo(typeof(string)); var item = Services.ContentManager.Get(id); var socket = item.As <SocketsPart>(); var connectors = socket.Sockets[connectorName].Connectors.List( q => q.ForPart <CommonPart>().OrderBy <CommonPartRecord>(c => c.CreatedUtc), q => q.ForPart <ConnectorPart>().Slice(0, limit)); var site = Services.WorkContext.CurrentSite; var url = new UrlHelper(_requestContext); if (context.Format == "rss") { var link = new XElement("link"); context.Response.Element.SetElementValue("title", GetTitle(item.GetTitle(), site)); context.Response.Element.Add(link); context.Response.Element.SetElementValue("description", item.GetBody()); context.Response.Contextualize(requestContext => link.Add(url.AbsoluteAction(() => url.ItemDisplayUrl(item)))); } else { context.Builder.AddProperty(context, null, "title", GetTitle(item.GetTitle(), site)); context.Builder.AddProperty(context, null, "description", item.GetBody()); context.Response.Contextualize(requestContext => context.Builder.AddProperty(context, null, "link", url.AbsoluteAction(() => url.ItemDisplayUrl(item)))); } foreach (var child in connectors) { context.Builder.AddItem(context, child.RightContent.ContentItem); } }
public ActionResult Rsd(string path) { Logger.Debug("RSD requested"); var cAsePath = _rsdConstraint.FindPath(path); if (cAsePath == null) { return(HttpNotFound()); } CasePart cAsePart = _cAseService.Get(cAsePath); if (cAsePart == null) { return(HttpNotFound()); } const string manifestUri = "http://archipelago.phrasewise.com/rsd"; var urlHelper = new UrlHelper(ControllerContext.RequestContext, _routeCollection); var url = urlHelper.AbsoluteAction("", "", new { Area = "XmlRpc" }); var options = new XElement( XName.Get("service", manifestUri), new XElement(XName.Get("engineName", manifestUri), "Orchard CMS"), new XElement(XName.Get("engineLink", manifestUri), "http://orchardproject.net"), new XElement(XName.Get("homePageLink", manifestUri), "http://orchardproject.net"), new XElement(XName.Get("apis", manifestUri), new XElement(XName.Get("api", manifestUri), new XAttribute("name", "MetaWecAse"), new XAttribute("preferred", true), new XAttribute("apiLink", url), new XAttribute("cAseID", cAsePart.Id)))); var doc = new XDocument(new XElement( XName.Get("rsd", manifestUri), new XAttribute("version", "1.0"), options)); Response.Cache.SetCacheability(HttpCacheability.NoCache); return(Content(doc.ToString(), "text/xml")); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="query"></param> /// <param name="data"></param> /// <param name="total"></param> /// <param name="actionName"></param> /// <param name="controllerName"></param> /// <param name="routeValues"></param> /// <returns></returns> public static PagedResult <T> ToPagedResult <T>(this PageOptions query, IEnumerable <T> data, int total, string actionName, string controllerName, object routeValues = null) where T : class, new() { var result = new PagedResult <T>(query.Page, query.PageSize, total, data); var values = new RouteValueDictionary(routeValues) { ["Page"] = query.Page, ["PageSize"] = query.PageSize, //["Fields"] = query.Fields, ["Sort"] = query.Sort }; values["Page"] = 1; var first = UrlHelper.AbsoluteAction(actionName, controllerName, values); result.Links.First = new Link(first); values["Page"] = query.Page - 1; if (query.Page - 1 > 0) { var previous = UrlHelper.AbsoluteAction(actionName, controllerName, values); result.Links.Previous = new Link(previous); } values["Page"] = query.Page; var self = UrlHelper.AbsoluteAction(actionName, controllerName, values); result.Links.Self = new Link(self); values["Page"] = query.Page + 1; if (query.Page + 1 < result.Page.TotalPages) { var next = UrlHelper.AbsoluteAction(actionName, controllerName, values); result.Links.Next = new Link(next); } values["Page"] = result.Page.TotalPages; var last = UrlHelper.AbsoluteAction(actionName, controllerName, values); result.Links.Last = new Link(last); return(result); }
private static XRpcStruct CreateBlogStruct( BlogPostPart blogPostPart, UrlHelper urlHelper) { var url = urlHelper.AbsoluteAction(() => urlHelper.BlogPost(blogPostPart)); var blogStruct = new XRpcStruct() .Set("postid", blogPostPart.Id) .Set("title", blogPostPart.Title) .Set("wp_slug", blogPostPart.Slug) .Set("description", blogPostPart.Text) .Set("link", url) .Set("permaLink", url); if (blogPostPart.PublishedUtc != null) { blogStruct.Set("dateCreated", blogPostPart.PublishedUtc); blogStruct.Set("date_created_gmt", blogPostPart.PublishedUtc); } return(blogStruct); }
public void SendCompleteRegistrationEmail(User user) { var path = Path.Combine( HttpContext.Current.Server.MapPath("~/App_Data"), @"Templates\RegistrationMessageTemplate.html"); var messageBody = FileOperator.ReadFile(path); var token = Cryptography.GenerateTokenById(user.Id.Value, ConfigurationReader.EncryptKey); var url = new UrlHelper(HttpContext.Current.Request.RequestContext); var activationUrl = url.AbsoluteAction( "Activate", "Account", new { token, area = string.Empty }); var activationLink = $@"<a href=""{activationUrl}""><strong>{activationUrl}</strong></a><br/> "; messageBody = messageBody .Replace("$$FullName", $"{user.FirstName} {user.LastName}") .Replace("$$activationLink", activationLink) .Replace("$$username", user.UserName); var email = new Email { Content = Encoding.UTF8.GetBytes(messageBody), RecepientId = user.Id.Value, SendUserId = ConfigurationReader.AutomationUserId, SentMailMessageType = EnumHelper.GetMessageTypeIdByEnum(SentMailMessageType.UserRegistrationMail) }; using (var transaction = contextManager.NewTransaction()) { userService.UpdatePasswordToken(user.Id.Value, token); email.Id = emailService.Insert(email); transaction.Commit(); } mailSender.SendMail(email.Id.Value, user.Email, Resource.ConfirmRegistrationMailSubject); }
private void SendEmailToVibrantHealth(UserMembership userMembership, PromoCode promoCode) { var template = Dictionary.MembershipCreatedEmail; var title = "We have received a new subscription!"; _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new { Title = title, Customer = userMembership.User.FullName, CustomerEmail = userMembership.User.EmailAddress, SubscriptionType = userMembership.MembershipOption.SubscriptionTypeNameLocal, TotalPrice = promoCode?.FormattedPrice ?? userMembership.MembershipOption.FormattedPrice, LinkToSummary = _urlHelper.AbsoluteAction("Index", "UserMemberships"), Company = _config.CompanyName, ImageUrl = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl) }), _config.SupportEmailAddress, _config.CompanyName, _config.SupportEmailAddress, _config.CompanyName); }
private XRpcArray MetaWecAseGetUserCases(UrlHelper urlHelper, string userName, string password) { IUser user = ValidateUser(userName, password); XRpcArray array = new XRpcArray(); foreach (CasePart cAse in _cAseService.Get()) { // User needs to at least have permission to edit its own cAse posts to access the service if (_authorizationService.TryCheckAccess(Permissions.EditCasePost, user, cAse)) { CasePart cAsePart = cAse; array.Add(new XRpcStruct() .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Case(cAsePart))) .Set("cAseid", cAse.Id) .Set("cAseName", _contentManager.GetItemMetadata(cAse).DisplayText)); } } return(array); }
private XRpcArray MetaWeblogGetUserBlogs(UrlHelper urlHelper, string userName, string password) { IUser user = ValidateUser(userName, password); XRpcArray array = new XRpcArray(); foreach (BlogPart blog in _blogService.Get()) { // User needs to at least have permission to edit its own blog posts to access the service if (_authorizationService.TryCheckAccess(Permissions.EditBlogPost, user, blog)) { BlogPart blogPart = blog; array.Add(new XRpcStruct() .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blogPart))) .Set("blogid", blog.Id) .Set("blogName", blog.Name)); } } return(array); }