Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Richard 38 posts 78 karma points
    May 31, 2010 @ 10:24
    Richard
    0

    Redirect a response without using HttpContext.Current.ResponseRedirect()

    Hi,

    I know there is a better way here, but as I continue to sift through docs and examples, I thought I'd ask too :-)

    Scenario: My content tree looks like:

    /en
    -- textnode-with-umbracoAlias-XYZ

    /de
    --textnode-with-umbracoAlias-XYZ

    When the browser language is swapped from en to de, I can (via an Umbraco Macro implemented in C#) redirect to the the new language tree "/de" via HttpContext.Current.Response.Redirect("/de"); but as soon as an umbracoAlias is involved, this redirect doesn't work: I can't do a Redirect("/textnode-with-umbracoAlias-XYZ") since the new link is actually "/de/textnode-with-umbracoAlias-XYZ", but the Http Redirect to "/de/textnode-with-umbracoAlias-XYZ" no longer matches the alias, so I get a 404 page not found.

    Any tips, ideas? What I need is to swap the "/en" for the "/de" top level parent internally somehow (umbraco lib function?) and then redirect to "/textnode-with-umbracoAlias-XYZ" using the Http Redirect. OR better, do both using an umbraco lib function. My C# function is called from XSLT, of course, so if this all works better/easier in XSLT, no big deal. I'm just not the XSLT expert...

    Thanks!

    R

     

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 31, 2010 @ 10:43
    Sebastiaan Janssen
    0

    If your content URL's always match in all of the languages (except for the /en and /de) you could do a simple url rewrite.. So your  link would look like "/en/textnode-with-umbracoAlias-XYZ?lang=de" and the urlrewriter would turn that into "/de/textnode-with-umbracoAlias-XYZ".

    Add something this to /config/urlrewriting.config:

        <add name="contentstringrewrite"
          virtualUrl="^~/([A-Za-z]{2,3})/(.*)\?lang=([A-Za-z]{2,3})"
          rewriteUrlParameter="ExcludeFromClientQueryString"
          destinationUrl="~/$3/$2"
          ignoreCase="true" />
  • Richard 38 posts 78 karma points
    May 31, 2010 @ 11:18
    Richard
    0

    Thanks Sebastiaan,

    for the tip. I'll take a look, but somehow I have the feeling, that I'm missing something fundamental in the Umbraco lib. There must be a way to say "if I get url X, serve up URL y (or alias y)" internally. Also, the rewrite above won't solve my problem yet. I think my description wasn't clear on this point: the /XYZ is the alias I need to handle, so if the browser language changes from "en" to "de" then the /XYZ (same alias, two different pages in different language trees) needs to be hit in the proper language tree, but when I do /de/XYZ (rewriter or not), I get the 404...

    Best regards!

    R

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 31, 2010 @ 11:24
    Sebastiaan Janssen
    0

    Well, all of the redirect that I know of are described in a blog post that I did a while ago and the ones using url rewriting.

    If there's a pattern that you can match, you'll definately be able to use urlRewriting. I did have to write a simple rewrite handler recently to do a redirect based on a property value in a document. It was easy though, I just redirect to the handler and the handler sends the user straight to the correct page.

  • Richard 38 posts 78 karma points
    May 31, 2010 @ 14:25
    Richard
    0

    Thanks for your tips Sebastiaan, but it doesn't look like urlRewriting -- even with a major hack -- will do the trick. I wish it would, because this is eating time. After looking at the situation more closely, it is pretty clear what is happening: Every time I enter the alias /XYZ, the Umbraco back end loses track of the current rootNode, and starts with the very top node in the content tree. This means, in our case, that the language context is lost. So my whiz-bank handler kicks in and sets the root node to be the same as the current browser language, "de" fore example. I do this with a C# HttpContext.Request.Redirect("/de");. After that, Umbraco has set the new rootNode to "/de" (any way to do this in C# without the Redirect??). The problem is, that the Alias has been lost, since, if I redirect to /de/XYZ, I get a 404 (the Alias is XYZ, in each language tree). And I can't use a query parameter to my Redirect a second time (would be a real hack anyway) after the rootNode is set like Redirect("/de?ReturnHere=XYZ"), since it starts the process over again, as soon as I rediect to alias /XYZ again, Umbraco loses its current rootNode... and we're  back to step one.

    Is there any way to tell the umbracoAlias mechanism to start searching at a certain node or node level? Or better, to set the rootNode for the entire session? What am I missing here? I'm using the default Umbraco config files (umbraco v 4.0.3 (Assembly version: 1.0.3625.27276))

    Thanks for any ideas here!

    R

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 31, 2010 @ 15:23
    Sebastiaan Janssen
    0

    I haven't had the time to properly digest your post, but here's a suggestion for changing the structure of your site:

    English Site
     - /en

      - Page 1
      - Page 2
      - etc

    German Site
     - /de
      - Page 1
      - Page 2
      - etc

    In umbracoSettings.config make sure that useDomainPrefixes is set to true.

    You could then make subdomains (en.yoursite.com, de.yoursite.com) and set the domain names on "English site" and "German site" (right-click -> Manage hostnames). In essence, you will have two completely seperate sites and you should not be able to browse to a completely different site.

  • Richard 38 posts 78 karma points
    May 31, 2010 @ 16:21
    Richard
    0

    Hi Sebasiaan,

    Well, that is the structure of my site, but using different domains to solve this problem appears to be overkill at the moment: it will probably just cause other problems :-) I still think I am missing some obvouis Umbraco feature that would make this possible -- possible to influence the rootNode selection or the alias selection path...

    Thanks!

    R

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jun 01, 2010 @ 09:53
    Sebastiaan Janssen
    0

    Here's a wild idea: try adding a hostname anyway, but make it yourdomain.com/en and yourdomain.com/de

    It generates the correct URL's if you do that, not sure which domain the NiceUrl will pick if you have other hostnames, but you should be able to just go with these and not have to add any other hostnames.

Please Sign in or register to post replies

Write your reply to:

Draft