i'm using the MVC Sitemap Provider 4 and want to show always the canonical tag, not only when a second link is existing. Is there somebody who can help me?
Show always canonical tag with mvc sitemap provider
846 Views Asked by Andy At
1
There are 1 best solutions below
Related Questions in ASP.NET-MVC
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Related Questions in MVCSITEMAPPROVIDER
- Add additional fields to Linq group by
- couldn't copy pdb file to another directory while consuming wcf web service
- Why are the aliases for string and object in lowercase?
- WPF MessageBox Cancel checkbox check
- Resolve object using DI container with object instance
- Creating a parametrized field name for a SELECT clause
- Does compiler optimize operation on const variable and literal const number?
- Get data from one form to another form in C#
- Writing/Overwriting to specific XML file from ASP.NET code behind
- Deleting Orphans with Fluent NHibernate
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The best way to do this is to edit (or create another) template to build the canonical tag. If you installed using the NuGet package, in your /Views/Shared/DisplayTemplates folder you will have a CanonicalHelperModel.cshtml file (or with a .ascx extension if you are using webforms instead of razor). The default looks like this:
You can change it so it uses the URL property if no canonical URL was resolved by adding an else block.
You may need to devise a better way to get the base URL (domain name and http/https) and reliably concatenate it with the URL property, as the canonical tag requires an absolute URL. You could just grab the current Request.RawUrl instead of Model.CurrentNode.Url, but you will need to ensure it is properly sanitized (and HTML encoded) before displaying it on the page to prevent XSS attacks. However, if you use the Request.RawUrl just to get the base URL (by loading it into a Uri object and then using the base URL parts), you should be fine.
This will only work for pages that have a matching node defined in the SiteMap. If reading the nodes from an external source such as a database, you should ensure that each record in the database has a node in the SiteMap so there is a one-to-one correlation (at least for the pages you want indexed in search engines). You should not be using preservedRouteParameters in this case. For more information on that subject see How to Make MvcSiteMapProvider Remember a User's Position.
On a side note, there really is no need to do what you are asking because the only pages that require canonical tags are the duplicates.