Copied to clipboard

Flag this post as spam?

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


  • hetaurhet 245 posts 267 karma points
    Nov 24, 2011 @ 16:53
    hetaurhet
    0

    access user friendly url in razor

    hello....

    I want to access current url which is re-written using user-friendly url rules....

    By using following line it shows url with querystring params, i.e. http://mydomain.com/default/?id=2

    String url = Request.Url.AbsoluteUri;


    But I need like.... http://mydomain.com/default/2/ ; ... how can I get thje url which is displayed in addressbar of browser?

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Nov 24, 2011 @ 17:00
    Sebastiaan Janssen
    0

    Razor is just HTML with a bit of C# mixed in, so you should be able to get it in the normal way that you would in C#:

    @Request.Url.ToString()
    

    Edit: Hmm, I didn't read properly, seems like you already tried something similar. What rewriter are you using? Umbraco's?? Try @HttpContext.Current.Request.Path as well.

  • hetaurhet 245 posts 267 karma points
    Nov 25, 2011 @ 06:21
    hetaurhet
    0

    I tried your suggestion but does not give what I need. I have used IIS manager for re-write and redirect user-friendly url.  ....

    so say mu url appears as http://mydomain.com/books/education/  ; where education is book category i.e. category is parameter. I want to access http://mydomain.com/books/education/ and not http://mydomain.com/books/?category=education. ; How to achieve this?

    OR how can use javascript in razor to access address bar url exactly as it is?

     

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Nov 28, 2011 @ 21:18
    Sebastiaan Janssen
    0

    According to this post, using Request.Url should give you the rewritten URL. Are you using the 2.0 version of the URL Rewrite module for IIS? It's much improved over the original version.

  • hetaurhet 245 posts 267 karma points
    Nov 29, 2011 @ 05:54
    hetaurhet
    1

    hey I solved the problem... using following...

    "http://" +HttpContext.Current.Request.ServerVariables["HTTP_HOST"]) + Request.RawUrl;

Please Sign in or register to post replies

Write your reply to:

Draft