Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesGet current page URLGet current page URL
Previous
 
Next
New Post
4/5/2011 1:07 AM
 
Thank you Kelly but it does not work. It does not return the ProductID and its value.

Is there another suggestion?
 
New Post
4/5/2011 2:36 AM
 
I had a different approach of getting the url. I tried to build it myself. I used the following code in order to do:

NavigateURL("", Request.QueryString.ToString.Replace("&", "=").Split("="))

I ask from the NavigateURL to add the QueryString parameters to the url but this has as a result to duplicate the existing parameters. When I have the following url:

http://localhost/dnndevelopement/Home/Test/tabid/64/language/en-US/ProductID/12/Default.aspx

the NavigateURL gives me the following url:

http://localhost/dnndevelopement/Home/Test/tabid/64/TabId/64/language/en-US/ProductID/12/language/en-US/Default.aspx

If you check the created url you will realize that the language and tabid has been added 2 times. The first copy used automatically by the NavigateURL and the other from the QueryString. Is there a way solve the duplicated problem or suggest a dnn function which will solve my problem? I really need this url and I have to find a way to get it.
 
New Post
5/3/2011 8:07 PM
 
Just picking up on this thread.



There's two things here.



First, if you want to know the original, requested Url (not the rewritten Url) you need to get it from the context.Items collection, like this:

string originalRequestedUrl = Context.Items["UrlRewrite:OriginalUrl"];

You should be defensive about this in case a Url Rewrite didn't happen for your request.  So always check for null return values.



Next, if you want to build a Url, you should just use the NavigateUrl overloads.  The mistake you're making is trying to use your existing Url to build the new one, when in fact you should be building it from the individual pieces.



So, what you should be doing is obtaining your product Id, tabid and then putting them back into the NavigateUrl() function.  Ideally, within your module you should have a function which will give you back a Url for a given tab and product id - then just call this.



This would then look like :

string url = DotNetNuke.Common.Globals.NavigateUrl(tabId, "", "productId", 12); (or thereabouts, working from memory here)



This will give you back the URl as it should be for that page.



It's important to always do this and never try to construct your Urls by using find/replace or other hacking operations.  The NavigateUrl function respects all of the settings within DNN surrounding Friendly Urls, which includes the correct portal alias, the current language, and anything else now or in the future.  Building your own Urls outside of the DNN API is a surefire method of making sure your module will one day be 'broken' with a DNN upgrade, as happend to many people in 4.8 when the 'humanFriendly' function was switched on by default.

 
New Post
5/17/2011 8:10 AM
 
Bruce Chapman wrote:

Just picking up on this thread.







There's two things here.







First, if you want to know the original, requested Url (not the rewritten Url) you need to get it from the context.Items collection, like this:



string originalRequestedUrl = Context.Items["UrlRewrite:OriginalUrl"];



You should be defensive about this in case a Url Rewrite didn't happen for your request.  So always check for null return values.







Next, if you want to build a Url, you should just use the NavigateUrl overloads.  The mistake you're making is trying to use your existing Url to build the new one, when in fact you should be building it from the individual pieces.







So, what you should be doing is obtaining your product Id, tabid and then putting them back into the NavigateUrl() function.  Ideally, within your module you should have a function which will give you back a Url for a given tab and product id - then just call this.







This would then look like :



string url = DotNetNuke.Common.Globals.NavigateUrl(tabId, "", "productId", 12); (or thereabouts, working from memory here)







This will give you back the URl as it should be for that page.







It's important to always do this and never try to construct your Urls by using find/replace or other hacking operations.  The NavigateUrl function respects all of the settings within DNN surrounding Friendly Urls, which includes the correct portal alias, the current language, and anything else now or in the future.  Building your own Urls outside of the DNN API is a surefire method of making sure your module will one day be 'broken' with a DNN upgrade, as happend to many people in 4.8 when the 'humanFriendly' function was switched on by default.



 

I was about to abandon my project because I was not been able to find a solution for my problem but I just realized that you replied to my message some days ago. The only problem is that you show the way to get the URL if we know the parameters but how can I get the URL when I do not know the parameters of another module. If another module has added some values in the URL I will not be able to know what the parameters are so I suppose that I have to find a way to include these values in the NavigateUrl function. Is there an easy way to do it?

 
New Post
5/17/2011 9:22 AM
 
Aristotelis Pitaridis wrote:

Bruce Chapman wrote:





It's important to always do this and never try to construct your Urls by using find/replace or other hacking operations.  The NavigateUrl function respects all of the settings within DNN surrounding Friendly Urls, which includes the correct portal alias, the current language, and anything else now or in the future.  Building your own Urls outside of the DNN API is a surefire method of making sure your module will one day be 'broken' with a DNN upgrade, as happend to many people in 4.8 when the 'humanFriendly' function was switched on by default.



 

I was about to abandon my project because I was not been able to find a solution for my problem but I just realized that you replied to my message some days ago. The only problem is that you show the way to get the URL if we know the parameters but how can I get the URL when I do not know the parameters of another module. If another module has added some values in the URL I will not be able to know what the parameters are so I suppose that I have to find a way to include these values in the NavigateUrl function. Is there an easy way to do it?

 

Yes, that's easy.

Just iterate through the Request.QueryString Keys collection.  For each key, get the value.  Thus you have the requested parameters for that page.  You can inspect them and construct your 'new' Url to pass into the NavigateUrl function.

In rough pseudo code:

string newQueryString = ""

foreach (key in querystring.keys)

{

    value = querystring[key]

    newQueryString = newQueryString + "&" + key + "=" + value   

}

url = NavigateUrl(tab, "", newQueryString

That's rough but should get you the right idea.  You might have to look at each key to work out whether or not you should be updating for your new value (ie, if you have an 'id' field you want to add to the querystring, you'll have to check to make sure there isn't an existing 'id' field in the keys collection).

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesGet current page URLGet current page URL


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out