"How do I build a string in HTML that includes the current "SessionID"?

Posted on 2004-11-29
Last Modified: 2008-03-17
I am building a website using   I now know how to build a string in the code-behind (C#) that includes the current "SessionID", it works like this:

String strSecureURL = "" + this.Request.ServerVariables["SERVER_NAME"].ToString() + "/(" + this.Request.ServerVariables["HTTP_ASPFILTERSESSIONID"].ToString() + ")" + this.Request.ServerVariables["URL"].ToString();

My question is "how can I build a similar string in the HTML code?".  In other words, "How do I build a string in HTML of the form "href="?
Question by:Finch
    LVL 3

    Accepted Solution

    I am not sure if I understand this question correctly, but if when you say 'in HTML of the form' you mean in the the HTML of the ASPX file for that form, you can simply insert your code in the ASPX file surrounded by <% and %>.


    String strSecureURL
    strSecureURL = "" + this.Request.ServerVariables["SERVER_NAME"].ToString() + "/(" + this.Request.ServerVariables["HTTP_ASPFILTERSESSIONID"].ToString() + ")" + this.Request.ServerVariables["URL"].ToString();

    Then in your anchor tag....

    <a href='<%=strSecureURL%>'>

    That ought to do it for you.
    LVL 21

    Assisted Solution

    You can build a string using javascript or VBscript. But using javascript or VB script we wont be able to access server variables. So it would require us to save these values in hidden variables.

    Assuming that the three values are stored in h1,h2,h3 and we are using javascript.

    function BuildString()
        var strUrl = '' + document.all.h1.value + "/(" + document.all.h2.value + "/("  + document.all.h3.value;
    return strUrl;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now