Solved

Validating User ID Carried Over Against Current User ID

Posted on 2012-03-23
1
261 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

749 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