Click here to Skip to main content
13,297,513 members (50,370 online)
Click here to Skip to main content
Add your own
alternative version


66 bookmarked
Posted 9 Sep 2004

Pass-Through Security Authentication (Single Sign-on) using ASP.NET

, 9 Sep 2004
Rate this:
Please Sign up or sign in to vote.
The Pass-Through authentication enables a user to sign-on to their intranet and access other web applications without being asked for login again.


The necessity came in when we had a Web Application that is intended to be used by Client's users (customers). They have logged into their network and are authenticated by their network. The Client’s intranet will have a link to access the Web application. When they click the link, they might be asked for User Name and Password. The web application has its own Login/password page, if you are not authenticated by this application network domain (Active Directory roles). But the Client would not like that as they need to remember four or five different username/passwords for every provider application that they need to use from their intranet. They want to access the application when they click a link from their intranet. When they access the same website from outside their intranet, it should prompt for the login.

Available Solutions:

  1. Use Passport Authentication (again the client users should be creating a passport account) and the web application should be registered in passport to use their service.
  2. Use SAML based Authentication Modules that allow Federated Security Authentication. This requires lot of work.
  3. Use a Security Key provider module that generates a Ticket to send it along with the user credentials from the client side. The Web application will use the same provider module to validate the Key and authenticate the login.
  4. Use a HTTP POST to send Identity values along with a Hash Value (credentials + private key) to the Web application. The application creates the Hash value using the credentials and private key, matches the passed Hash value, and authenticates the login attempt.


I am going for the fourth solution, as it is the cheapest method. It may not be the best but it is good over SSL connections. However, the solution needs some work at the client side to pass the values. The client code will pass four parameters using POST to the application Pass-Through Page: Client ID, Username, Timeline, and Key Hash. The Client ID is a number to identify a client (valid in the Web application), the Username may be the user’s network login username, Timeline is a date time in “yyyymmddHHss” GMT/UTC time format, and Key Hash is the hashed (SHA1) value of Client ID + User Name + Time line + Private Key. The private key will be the same key on both sides and there is a small compromise on this – keys will be securely stored in both applications (database or a secured file location on network) in encrypted form.

The POST values are received in the web application, validates if the Timeline is within the allowable window (+/- 2 minutes) and the application gets the copy of Private Key from the database, uses that key to create a Hash value of the Client ID, user name, timeline and the private key. This hash value is compared to the Hash key POSTed. If both values match, it allows the user to access the application by setting the over-ride login.

The important thing to remember is this works only if it is accessed over SSL. If not, anyone could sniff the Key hash and hack the session. However, they may not be able to get any other user’s data by getting the Hash Value. SHA1 is very hard to decrypt. Also, at the client side POST code, it should not take more time to create the POST URL and re-direct – otherwise it allows the user to use 'View Source' and get the Hash value. This may not be useful anyways but it is a possibility to find the Hashed value.

Source Code:

Most of the code is self explanatory and I have given the purpose of each project code.

  1. WebConfig:
        <add key="PassThroughAccountId" value="1"/>
        <add key="URLForward" 
        <add key="Key" value="WAga1weKy7Tcbonly1Af76jbj7jbb"/>
  2. Create Pass-through Values.

    In the project TestPassThrough, PassthroughTest.aspx.cs contains the code to generate the Hash values based on the credentials that is entered in the textboxes. Basically, I have used this method just to test the application. In production application, you might have to get the user details from the Network login credentials.

    private void Page_Load(object sender, System.EventArgs e)
      KeyToHash = ConfigurationSettings.AppSettings.Get("Key");
      if (!Page.IsPostBack)
        txtTimeline.Text = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
        Submit.Disabled = true;
    private void Submit_ServerClick(object sender, System.EventArgs e)
      string toSend;
      toSend = "PostToAppl.aspx" + "?var1=" + txtUsername.Text + 
               "&var2=" + txtTimeline.Text + "&var3=" + 
               TextBoxKey.Text + "&var4=" + txtClientId.Text;
      Submit.Disabled = true;
    private void GenHash_Click(object sender, System.EventArgs e)
      string Username = txtUsername.Text;
      string Timeline = txtTimeline.Text;
      // KeyToHash = "326FD166-85B8-4990-93DB-A8802C1C74CA";
      string SentHash = Username + Timeline + txtClientId.Text + KeyToHash;
      string base64HashValue = 
      TextBoxKey.Text = base64HashValue;
      Submit.Disabled = false;
    private void GetUTCTime_Click(object sender, System.EventArgs e)
      txtTimeline.Text = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
  3. Post to the application:

    I have sent the values in Query string to another aspx page (which automatically POSTs the values to the application). I did this to verify the values being sent. You can avoid by doing in a single step.

    private void Page_Load(object sender, System.EventArgs e)
      Username_Form = Request.QueryString.Get(0);
      Timeline_Form = Request.QueryString.Get(1);
      Hash_Form = Request.QueryString.Get(2);
      ClientId = Request.QueryString.Get(3);
      URLForward = ConfigurationSettings.AppSettings.Get("URLForward");
    //Code Behind :
    <%@ Page language="c#" Codebehind="PostToAppl.aspx.cs" 
       AutoEventWireup="false" Inherits="Passthrough.UI.Web.PostToAppl" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
      <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
      <meta name="CODE_LANGUAGE" Content="C#">
      <meta name="vs_defaultClientScript" content="JavaScript">
      <meta name="vs_targetSchema" 
     <body MS_POSITIONING="GridLayout" onload="Redirect();">
      <form action='<%=URLForward%>' method='post' 
                               Target='_blank' name='frmLogon'>
       <table border='1'>
         <td class='bold'>UserName</td>
         <td> </td>
         <td><input type='text' name='Username' value='<%=Username_Form%>' 
                                      size='30' MAXLENGTH='30' readOnly>
         <td class='bold'>Timeline</td>
         <td> </td>
         <td><input  type='text' name='Request Time' 
                           size='14' MAXLENGTH='14' readOnly></td>
         <td class='bold'>Hash</td>
         <td> </td>
         <td><input type='text'  name='Hashed Value' 
                    value='<%=Hash_Form%>' size='50' 
                    MAXLENGTH='50' readOnly></td>
         <td class='bold'>ClientId</td>
         <td> </td>
         <td><input type='text'  name='Hashed Value' 
                          value='<%=CleintId%>' size='50' 
                          MAXLENGTH='50' readOnly></td>
         <td colspan='3'></td>
       <script language="JavaScript">
        function Redirect()
  4. Application:

    Application code receives the posted values and gets the private key from the database or Web.config (for now, I have hard coded the key in the code itself), generates the HASH value, and compares it with the supplied value. If it is a match, set the User Object in the Session and allow the application to proceed.

Happy Coding.


Any suggestions are welcome, this is a part of an edited application. It may contain some incomplete or commented code as my intention was to explain and give an outline of the Pass-Through authentication. Any other better methods may be available. So use it with caution and explore all possibilities to prevent the sessions hacked.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
Jay is a Software Engineer, working on .Net technologies for since 2003. He has expertise in VC++/Microsoft technologies since 1994. Jay loves Fishing, photography & enjoys travel.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
ketan italiya29-Jul-13 20:53
professionalketan italiya29-Jul-13 20:53 
Generalis there any other way Pin
IMQ26-Sep-10 4:12
memberIMQ26-Sep-10 4:12 
QuestionHow to get Lastlogintime with Pin
kadumanish833-Jun-08 20:21
memberkadumanish833-Jun-08 20:21 
GeneralNice. Pin
habeab19-Feb-07 3:51
memberhabeab19-Feb-07 3:51 
GeneralWrong info Pin
bitemyassbobsmith20-Jun-06 11:23
memberbitemyassbobsmith20-Jun-06 11:23 
GeneralRe: Wrong info Pin
bitemyassbobsmith20-Jun-06 11:55
memberbitemyassbobsmith20-Jun-06 11:55 
GeneralAny Advice Pin
utbusta3-Jun-05 6:48
memberutbusta3-Jun-05 6:48 
GeneralWeb Service Pin
BeanoKing15-Mar-05 10:16
memberBeanoKing15-Mar-05 10:16 
GeneralNice. Pin
Anonymous10-Sep-04 5:05
sussAnonymous10-Sep-04 5:05 
GeneralAlways Test! Pin
Ashaman10-Sep-04 3:03
memberAshaman10-Sep-04 3:03 
GeneralRe: Always Test! Pin
Jayakanthan10-Sep-04 3:54
memberJayakanthan10-Sep-04 3:54 
GeneralBreak up the lines in your first code block Pin
Shog99-Sep-04 18:26
memberShog99-Sep-04 18:26 
GeneralRe: Break up the lines in your first code block Pin
Jayakanthan10-Sep-04 3:52
memberJayakanthan10-Sep-04 3:52 
GeneralRe: Break up the lines in your first code block Pin
Shog910-Sep-04 5:32
memberShog910-Sep-04 5:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 9 Sep 2004
Article Copyright 2004 by Jayakanthan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid