Solved

Validating User ID Carried Over Against Current User ID

Posted on 2012-03-23
1
257 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
1 Comment
 
LVL 18

Accepted Solution

by:
UnifiedIS earned 500 total points
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now