Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validating User ID Carried Over Against Current User ID

Posted on 2012-03-23
1
Medium Priority
?
272 Views
Last Modified: 2012-03-28
Hello,

I working on a website  page showing our terms of agreement.  The user needs to click on a checkbox agreeing to the terms, click on the "I Accept" button,  and then they're taken to our products.  

I am trying to check whether the user ID that was carried during the navigation process is the same as the current user. If they are the same, the user should be able to keep on going forwards, otherwise, they need to go back and login again.

This is the some page code I'm using:

..
<asp:Literal runat="server" ID="UserIDLiteral" />
..

..
        <p>
            <input type="checkbox" name="TermsAgreementCheckBox" id="TermsAgreementCheckBox" />
            <label for="TermsAgreementCheckBox">I accept the terms of this agreement.</label>
            <br />
            <br />            
            <asp:ImageButton AlternateText="Launch Product" runat="server" OnClientClick="return ValidateTerms();" ImageUrl="/images/products/button-launch-product.jpg" ID="LaunchProductImageButton" CausesValidation="false" />
        </p>  
..

<script type="text/javascript">
    function ValidateTerms() {
        if ($('#TermsAgreementCheckBox').attr('checked')) {
            return true;
        }
        else {
            alert('You must accept the terms.');
            return false;
        }
    }
</script>

---

In the code behind this page,  I'm storing the original User ID value passed through the query string in the UserIDLiteral during the setHiddenFields sub:

this.UserIDLiteral.Text = string.Format(hiddenTagFormat, "userid", this.Request.QueryString["userid"].ToString());

When the user loads this page in a multiuser computer, a lot of things could happen, including another customer  logging in while this page is minimized.  What I want to do is to compare the UserID stored in the UserIDLiteral with the current user that's clicking on the checkbox and button. If they're not the same, the user needs to login again. Otherwise, they can go forwards.

I can get the current user id using this;

string currentid = this.CurrentUser.UserID.ToString()

My problem is, how and where do I do the checking process?  I have some good experience with VB.NET, but not a lot with C#.

Additionally, here's more code behind this page

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {

               this.SetHiddenFields();
                this.AddFormActionChangeJavaScript();
                this.Page.Form.Method = "post";
               
            }
        }

     
        private void AddFormActionChangeJavaScript()
        {            
            StringBuilder sb = new StringBuilder(128);
            sb.AppendLine("$(document).ready(function () { ");      
            this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Change_Form_JS", sb.ToString(), true);
        }

Thanks for all your help.

Have a good weekend.

T.
0
Comment
Question by:TheUndecider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 2000 total points
ID: 37759940
sounds like the page load would work (if not postback) for the comparison and then if it fails, do a response.redirect
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 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