Developer forum

Forum » Development » How to get user friendly url from /default.aspx?AreaID=16

How to get user friendly url from /default.aspx?AreaID=16

Martin Nielsen
Reply

Hi DW,

I'm trying to make a module that can redirect a user to different websites (Area), based in their browser language.

I've got everything working except getting the correct URL for my areas.

I'd like my code to redirect to the final user friendly url, to avoid Dynamicweb doing more redirects to pretty up the URL.

So far i do this:

public void Redirect( Dynamicweb.Content.Area redirArea ) {
      if ( redirArea != null ) { 
        string url = "/Default.aspx?AreaID={0}";
        HttpContext.Current.Response.RedirectPermanent( string.Format( url, redirArea.ID ), true );
        
      }      
    }

But this results in ugly URLs like /int/forside?AreaID=16 after DW does 2 redirects to pretty up url. (And it's still pretty bad :-) )

My question is therefore two part.

1. How do i get the frontpage of a given area in the API?
2. How do i build the User friendly URL in the API?

// Martin


Replies

 
Nicolai Høeg Pedersen
Reply

You could do like this:

 

string.format("/Default.aspx?ID={0}", Frontend.Area.GetAreaById(1).Value("AreaFirstPage"))

 

And depending on the rest of your website settings, this would give you the right URL.

 

BR Nicolai

 
Martin Nielsen
Reply

Hi Nicolai,

Won't this still make DW rewrite the url from 

/Default.aspx?ID={0}

to 

/int/forside

?

I'd like to avoid that extra redirect, and just create the final URL in my code.

 

// Martin

 
Nicolai Høeg Pedersen
Reply

Like this then:

 

HttpContext.Current.Response.RedirectPermanent(SearchEngineFriendlyURLs.GetFriendlyUrl(Input.FormatInteger(Frontend.Area.GetAreaById(1).Value("AreaFirstActivePage"))))

 

 

 

 

 

You must be logged in to post in the forum