Copied to clipboard

Flag this post as spam?

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


  • Dan 1250 posts 3747 karma points admin c-trib
    Nov 06, 2009 @ 15:01
    Dan
    0

    Get current URL in ASP.NET

    Hi,

    This isn't an xslt question, but I'm not sure where else to post it.  Anyhow, I'm adding a bookmark tool to my pages and need to grab the current page URL inline in the template code.  Currently I have this:

    <a href="http://del.icio.us/post?url=<%=Request.ServerVariables["SCRIPT_NAME"]%>"><img src="/media/123/delicious.png" /></a>

    However, that just yeilds the following output:

    <a
    href="http://del.icio.us/post?url=/my-page.aspx"><img
    src="/media/123/delicious.png" /></a>

    I need it to output the full URL:

    <a
    href="http://del.icio.us/post?url=http://www.my-site.com/directory/my-page.aspx"><img
    src="/media/123/delicious.png" /></a>

     

    Does anyone know how this can be done?

    Thanks

  • Fredrik Sewén 39 posts 106 karma points
    Nov 06, 2009 @ 15:48
    Fredrik Sewén
    1

    Hi, 

    I think you have to do two Requests. One for the server name and one for the file, and also add the protocol you are using.

    Something like this:

    <a href="http://del.icio.us/post?url=http://<%= Request.ServerVariables("SERVER_NAME") +Request.ServerVariables["SCRIPT_NAME"] %>"><img src="/media/123/delicious.png" /></a>

    /Fredrik

  • Petr Snobelt 923 posts 1534 karma points
    Nov 06, 2009 @ 15:51
    Petr Snobelt
    0

    Try Request.Url but next time you should use google first :-)

    http://www.dotnetfunda.com/articles/article79.aspx

     

  • Dan 1250 posts 3747 karma points admin c-trib
    Nov 06, 2009 @ 16:26
    Dan
    0

    Thanks Fredrik, that works fine.  Petr, of course I Googled first.  I tried using 'Request.URL' but couldn't get it to work.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies