Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Validating User ID Carried Over Against Current User ID

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
TheUndecider
Asked:
TheUndecider
1 Solution
 
UnifiedISCommented:
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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now