Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...


.GetThisPageName(true) still returns .../p-1234.aspx - any alternative suggestions?

http://@Request.Url.Host@CommonLogic.GetThisPageName(true) still still returns ".../p-1234.aspx" - is there an alternative to try?

asked May 4, 2018 in MultiStore by Andre (125 points)

1 Answer

0 votes
GetThisPageName uses the current page (the SCRIPT_NAME ServerVariable to be excat) to generate the url. In the linked post it the urls still used .aspx pages so that wouldn't be an issue. If you are using the Morden MVC routes most .aspx pages should be redirecting to begin with also. So not entirely sure I follow the full context.

But I guess you could try to use Url.BuildProductLink instead. Which would look something like http://@Request.Url.Host@Url.BuildProductLink(Convert.ToInt32(AppLogic.GetCurrentPageID()), null ,null) . Do keep in mind I haven't tested this fully and you may need a if statement check or tryparse for AppLogic.GetCurrentPageID being emtpy.

Also if you are getting this complex with meta tags I suggest adding a custom class. Since a class can be easier to deal with than having all code in a MVC view. That way you can hadle each page type.
answered May 4, 2018 by mmcgeachy (5,045 points)
Thank you.

This is still returning (for example) ".../c-33.aspx" instead of ".../c-33-boots.aspx" - the SEName is stil being omitted, but I understand your point about a custom class where we can deal with this.

Does your URL have a SEname in it? If it is blank than the defualt code should do a 301 to URL to add the SEname. Which I thought CommonLogic.GetThisPageName(true) pulled through the SEname when present.

If the SEname is in the URL and just not showing in the in CommonLogic.GetThisPageName(true) the code below may work.

	var sename = string.Empty;
	var routeData = HttpContext.Current.Request.RequestContext.RouteData.Values;
	if (routeData != null || routeData.ContainsKey(RouteDataKeys.SearchEngineName))
		if(!string.IsNullOrWhiteSpace(routeData[RouteDataKeys.SearchEngineName] as string))
			sename = (routeData[RouteDataKeys.SearchEngineName] as string);

http://@Request.Url.Host@Url.BuildProductLink(Convert.ToInt32(AppLogic.GetCurrentPageID()), sename, null)

Which is basicly just passing through the SEname from routedata to Url.BuildProductLink

Thank you. 

routeData.ContainsKey(RouteDataKeys.SearchEngineName) was returning as false, but I realised where I was going wrong - I only now realised the BuildProductLink is only for product pages - duh!:

On product pages the following returns the URL with SEName in the required format:

<link rel="canonical" href="https://@Request.Url.Host@Url.BuildProductLink(Convert.ToInt32(AppLogic.GetCurrentPageID()), null ,null)" />

On category pages the following returns the full URL with SEName in the correct format::

<link rel="canonical" href="https://@Request.Url.Host@Url.BuildEntityLink("category",Convert.ToInt32(AppLogic.GetCurrentPageID()), null ,null)" />

Therefore, the (rough) solution was as follows:
switch (AppLogic.GetCurrentPageType())
case "category":
@Html.Raw("<link rel=\"canonical\" href=\"https://" + Request.Url.Host + Url.BuildEntityLink("category", Convert.ToInt32(AppLogic.GetCurrentPageID()), null, null) + "\" />");
case "product":
@Html.Raw("<link rel=\"canonical\" href=\"https://" + Request.Url.Host + Url.BuildProductLink(Convert.ToInt32(AppLogic.GetCurrentPageID()), null, null) + "\" />");
Thank you for your help.