Example #1
0
        public IReadOnlyCollection <SitemapNode> GetSitemapNodes(UrlHelper urlHelper)
        {
            List <SitemapNode> nodes = new List <SitemapNode>();

            nodes.Add(
                new SitemapNode()
            {
                Url      = urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "Index" }),
                Priority = 1
            });

            nodes.Add(
                new SitemapNode()
            {
                Url      = urlHelper.AbsoluteRouteUrl("Default", new { controller = "Account", action = "Register" }),
                Priority = 0.9
            });

            var pages = _pagesService.GetAll().Select(p => new SitemapNode()
            {
                Url       = urlHelper.AbsoluteRouteUrl("Default", new { controller = "Content", action = "Index", id = p.Url }),
                Frequency = SitemapFrequency.Weekly,
                Priority  = 0.8
            });

            nodes.AddRange(pages);

            return(nodes);
        }
Example #2
0
        public void AbsoluteRouteUrlWithRouteDictionary()
        {
            string expectedUrl = String.Format("http://localhost{0}/app/home/oldaction/12345", MvcHelper.AppPathModifier);
            var    values      = new RouteValueDictionary(new { id = "12345" });

            string generatedUrl = _helper.AbsoluteRouteUrl(values);

            Assert.AreEqual(expectedUrl, generatedUrl);
        }
Example #3
0
 /// <summary>
 /// Gets the URL to the tile XML for the specified item in the Atom feed for the site.
 /// </summary>
 /// <param name="feedEntry">The number of the Atom feed entry.</param>
 /// <returns>A URL to the tile XML.</returns>
 private string GetTileUrl(int feedEntry)
 {
     // We are using the service provided by http://buildmypinnedsite.com which queries our Atom feed (Which we
     // pass to it, along with the feed entry number) and returns tile XML using the Atom feed entry.
     // An alternative is to generate your own custom tile XML and return a URL to it here. You can take a look
     // at the tile template catalogue (https://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx) to
     // see the types of tiles you can generate and use the NotificationsExtensions.Portable NuGet package
     // (https://github.com/RehanSaeed/NotificationsExtensions.Portable) to generate the tile XML.
     return
         ($"http://notifications.buildmypinnedsite.com/?feed={_urlHelper.AbsoluteRouteUrl(HomeControllerRoute.GetFeed)}&amp;id={feedEntry}");
 }
Example #4
0
        public IReadOnlyCollection <string> GetSitemapNodes(UrlHelper urlHelper)
        {
            var nodes = new List <string>();

            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "News", action = "SixNews" }));
            foreach (var message in _notDeletedMessages)
            {
                nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Message", action = "Show", id = message.Id }));
            }

            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Gallery", action = "Show" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Video", action = "Show" }));

            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "TimeTable" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "Contacts" }));

            return(nodes);
        }
        public IReadOnlyCollection <SitemapNode> GetSitemapNodes(UrlHelper urlHelper)
        {
            List <SitemapNode> nodes = new List <SitemapNode>();

            nodes.Add(
                new SitemapNode()
            {
                Url = new System.UriBuilder(Request.Url.AbsoluteUri)
                {
                    Path  = Url.Content("~/"),
                    Query = null,
                }.ToString(),
                Priority = 1
            });
            nodes.Add(
                new SitemapNode()
            {
                Url = new System.UriBuilder(Request.Url.AbsoluteUri)
                {
                    Path  = Url.Content("~/Constructor"),
                    Query = null,
                }.ToString(),
                Priority = 0.9
            });
            foreach (dynamic project in getPublicPolls())
            {
                nodes.Add(
                    new SitemapNode()
                {
                    Url       = urlHelper.AbsoluteRouteUrl("getPoll", new { poll = project.UrlCode }),
                    Frequency = SitemapFrequency.Weekly,
                    Priority  = 0.8
                });
            }

            return(nodes);
        }
Example #6
0
        /// <summary>
        /// Gets the robots text for the current site. This tells search engines (or robots) how to index your site.
        /// The reason for dynamically generating this code is to enable generation of the full absolute sitemap URL
        /// and also to give you added flexibility in case you want to disallow search engines from certain paths. See
        /// http://rehansaeed.com/dynamically-generating-robots-txt-using-asp-net-mvc/
        /// Note: Disallowing crawling of JavaScript or CSS files in your sites robots.txt directly harms how well
        /// Google's algorithms render and index your content and can result in suboptimal rankings.
        /// </summary>
        /// <returns>The robots text for the current site.</returns>
        public string GetRobotsText()
        {
            var stringBuilder = new StringBuilder();

            // Allow all robots.
            stringBuilder.AppendLine("user-agent: *");

            // Tell all robots not to index any directories.
            // stringBuilder.AppendLine("disallow: /");

            // Tell all robots not to index everything under the following directory.
            // stringBuilder.AppendLine("disallow: /SomeRelativePath");

            // Tell all robots to to index any of the error pages.
            stringBuilder.AppendLine("disallow: /error/");

            // Tell all robots they can visit everything under the following sub-directory, even if the parent
            // directory is disallowed.
            // stringBuilder.AppendLine("allow: /SomeRelativePath/SomeSubDirectory");

            // Tell all robots the number of seconds to wait between successive requests to the same server. This can
            // be useful if your site cannot handle large loads placed on it by robots. Note that this is a
            // non-standard extension and not all robots respect it.
            // stringBuilder.AppendLine("crawl-delay: 10"); // Delay by 1- seconds.

            // SECURITY ALERT - BE CAREFUL WHAT YOU ADD HERE
            // The line below stops all robots from indexing the following secret folder. For example, this could be
            // your Elmah error logs. Very useful to any hacker. You should be securing these pages using some form of
            // authentication but hiding where these things are can help through a bit of security through obscurity.
            // stringBuilder.AppendLine("disallow: /MySecretStuff");

            // Add a link to the sitemap. Unfortunately this must be an absolute URL.
            stringBuilder.Append("sitemap: ");
            stringBuilder.AppendLine(_urlHelper.AbsoluteRouteUrl("").TrimEnd('/'));

            return(stringBuilder.ToString());
        }
Example #7
0
        public IReadOnlyCollection <string> GetSitemapNodes(UrlHelper urlHelper)
        {
            List <string> nodes = new List <string>();

            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "Index" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "About" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Home", action = "Contact" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Authorize", action = "SignIn" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Authorize", action = "Register" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Genre", action = "AllGenres" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Movies", action = "TopMovies" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Persons", action = "PersonAll" }));
            nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Genre", action = "AllGenres" }));


            foreach (int Id in repository.getIds <Movie>())
            {
                nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Movies", action = "Movie", id = Id }));
            }
            foreach (int personId in repository.getIds <People>())
            {
                nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Persons", action = "Person", id = personId }));
            }
            foreach (int Id in repository.getIds <Users>())
            {
                nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Users", action = "Users", id = Id }));
            }
            foreach (string genre in repository.getItems <Genre>().Distinct().Select(g => g.Name))
            {
                nodes.Add(urlHelper.AbsoluteRouteUrl("Default", new { controller = "Movies", action = "MoviesByGenre", id = genre }));
            }
            return(nodes);
        }
Example #8
0
        /// <summary>
        /// Gets the Open Search XML for the current site. You can customize the contents of this XML here. See
        /// http://www.hanselman.com/blog/CommentView.aspx?guid=50cc95b1-c043-451f-9bc2-696dc564766d
        /// http://www.opensearch.org
        /// </summary>
        /// <returns>The Open Search XML for the current site.</returns>
        public string GetOpenSearchXml()
        {
            // Short name must be less than or equal to 16 characters.
            var shortName   = "Search";
            var description = "Search the ASP.NET MVC  Site";
            // The link to the search page with the query string set to 'searchTerms' which gets replaced with a user
            // defined query.
            var searchUrl = _urlHelper.AbsoluteRouteUrl(
                "",
                new { query = "{searchTerms}" });
            // The link to the page with the search form on it. The home page has the search form on it.
            var searchFormUrl = _urlHelper.AbsoluteRouteUrl(HomeControllerRoute.GetSearch);
            // The link to the favicon.ico file for the site.
            var favicon16Url = _urlHelper.AbsoluteContent("~/content/icons/favicon.ico");
            // The link to the favicon.png file for the site.
            var favicon32Url = _urlHelper.AbsoluteContent("~/content/icons/favicon-32x32.png");
            // The link to the favicon.png file for the site.
            var favicon96Url = _urlHelper.AbsoluteContent("~/content/icons/favicon-96x96.png");

            XNamespace ns       = "http://a9.com/-/spec/opensearch/1.1";
            var        document = new XDocument(
                new XElement(
                    ns + "OpenSearchDescription",
                    new XElement(ns + "ShortName", shortName),
                    new XElement(ns + "Description", description),
                    new XElement(
                        ns + "Url",
                        new XAttribute("type", "text/html"),
                        new XAttribute("method", "get"),
                        new XAttribute("template", searchUrl)),
                    // Search results can also be returned as RSS. Here, our start index is zero for the first result.
                    // new XElement(ns + "Url",
                    //     new XAttribute("type", "application/rss+xml"),
                    //     new XAttribute("indexOffset", "0"),
                    //     new XAttribute("rel", "results"),
                    //     new XAttribute("template", "http://example.com/?q={searchTerms}&amp;start={startIndex?}&amp;format=rss")),
                    // Search suggestions can also be returned as JSON.
                    // new XElement(ns + "Url",
                    //     new XAttribute("type", "application/json"),
                    //     new XAttribute("indexOffset", "0"),
                    //     new XAttribute("rel", "suggestions"),
                    //     new XAttribute("template", "http://example.com/suggest?q={searchTerms}")),
                    new XElement(
                        ns + "Image",
                        favicon16Url,
                        new XAttribute("height", "16"),
                        new XAttribute("width", "16"),
                        new XAttribute("type", "image/x-icon")),
                    new XElement(
                        ns + "Image",
                        favicon32Url,
                        new XAttribute("height", "32"),
                        new XAttribute("width", "32"),
                        new XAttribute("type", "image/png")),
                    new XElement(
                        ns + "Image",
                        favicon96Url,
                        new XAttribute("height", "96"),
                        new XAttribute("width", "96"),
                        new XAttribute("type", "image/png")),
                    new XElement(ns + "InputEncoding", "UTF-8"),
                    new XElement(ns + "SearchForm", searchFormUrl)));

            return(document.ToString(Encoding.UTF8));
        }
Example #9
0
        /// <summary>
        ///     Gets the feed containing meta data about the feed and the feed entries.
        /// </summary>
        /// <param name="cancellationToken">A <see cref="CancellationToken" /> signifying if the request is cancelled.</param>
        /// <returns>A <see cref="SyndicationFeed" />.</returns>
        public async Task <SyndicationFeed> GetFeed(CancellationToken cancellationToken)
        {
            var feed = new SyndicationFeed
            {
                // id (Required) - The feed universally unique identifier.
                Id = FeedId,
                // title (Required) - Contains a human readable title for the feed. Often the same as the title of the
                //                    associated website. This value should not be blank.
                Title = SyndicationContent.CreatePlaintextContent("ASP.NET MVC Boilerplate"),
                // items (Required) - The items to add to the feed.
                Items = await GetItems(cancellationToken).ConfigureAwait(true),
                // subtitle (Recommended) - Contains a human-readable description or subtitle for the feed.
                Description = SyndicationContent.CreatePlaintextContent(
                    "This is the ASP.NET MVC Boilerplate feed description."),
                // updated (Optional) - Indicates the last time the feed was modified in a significant way.
                LastUpdatedTime = DateTimeOffset.Now,
                // logo (Optional) - Identifies a larger image which provides visual identification for the feed.
                //                   Images should be twice as wide as they are tall.
                ImageUrl = new Uri(_urlHelper.AbsoluteContent("~/content/icons/atom-logo-96x48.png")),
                // rights (Optional) - Conveys information about rights, e.g. copyrights, held in and over the feed.
                Copyright = SyndicationContent.CreatePlaintextContent(
                    string.Format("© {0} - {1}", DateTime.Now.Year, Application.Name)),
                // lang (Optional) - The language of the feed.
                Language = "en-GB"
                           // generator (Optional) - Identifies the software used to generate the feed, for debugging and other
                           //                        purposes. Do not put in anything that identifies the technology you are using.
                           // Generator = "Sample Code",
                           // base (Buggy) - Add the full base URL to the site so that all other links can be relative. This is
                           //                great, except some feed readers are buggy with it, INCLUDING FIREFOX!!!
                           //                (See https://bugzilla.mozilla.org/show_bug.cgi?id=480600).
                           // BaseUri = new Uri(this.urlHelper.AbsoluteRouteUrl(HomeControllerRoute.GetIndex))
            };

            // self link (Required) - The URL for the syndication feed.
            feed.Links.Add(SyndicationLink.CreateSelfLink(
                               new Uri(_urlHelper.AbsoluteRouteUrl(HomeControllerRoute.GetFeed)),
                               ContentType.Atom));

            // alternate link (Recommended) - The URL for the web page showing the same data as the syndication feed.
            feed.Links.Add(SyndicationLink.CreateAlternateLink(
                               new Uri(_urlHelper.AbsoluteRouteUrl(HomeControllerRoute.GetIndex)),
                               ContentType.Html));

            // hub link (Recommended) - The URL for the PubSubHubbub hub. Used to push new entries to subscribers
            //                          instead of making them poll the feed. See feed updated method below.
            feed.Links.Add(new SyndicationLink(new Uri(PubSubHubbubHubUrl), "hub", null, null, 0));

            // first, last, next previous (Optional) - Atom 1.0 supports paging of your feed. This is good if your feed
            //                                         becomes very large and needs splitting up into pages. To add
            //                                         paging, you must add links to the first, last, next and previous
            //                                         feed pages.
            // feed.Links.Add(new SyndicationLink(new Uri("http://example.com/feed"), "first", null, null, 0));
            // feed.Links.Add(new SyndicationLink(new Uri("http://example.com/feed?page=10"), "last", null, null, 0));
            // if ([HAS_PREVIOUS_PAGE])
            //     feed.Links.Add(new SyndicationLink(new Uri("http://example.com/feed?page=1")), "previous", null, null, 0));
            // if ([HAS_NEXT_PAGE])
            //     feed.Links.Add(new SyndicationLink(new Uri("http://example.com/feed?page=3"), "next", null, null, 0));

            // author (Recommended) - Names one author of the feed. A feed may have multiple author elements. A feed
            //                        must contain at least one author element unless all of the entry elements contain
            //                        at least one author element.
            feed.Authors.Add(GetPerson());

            // category (Optional) - Specifies a category that the feed belongs to. A feed may have multiple category
            //                       elements.
            feed.Categories.Add(new SyndicationCategory("CategoryName"));

            // contributor (Optional) - Names one contributor to the feed. An feed may have multiple contributor
            //                          elements.
            feed.Contributors.Add(GetPerson());

            // icon (Optional) - Identifies a small image which provides iconic visual identification for the feed.
            //                   Icons should be square.
            feed.SetIcon(_urlHelper.AbsoluteContent("~/content/icons/atom-icon-48x48.png"));

            // Add the Yahoo Media namespace (xmlns:media="http://search.yahoo.com/mrss/") to the Atom feed.
            // This gives us extra abilities, like the ability to give thumbnail images to entries.
            // See http://www.rssboard.org/media-rss for more information.
            feed.AddYahooMediaNamespace();

            return(feed);
        }