Verify Access

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetstairAccessVerifyer;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int iUserId = 101; //- Assuming the user Id = 101
            if (VerifyAccess.IsTheDeviceAccessVerified(iUserId, Request.UserHostName))
            {
                //- Let the user through
                Response.Write("Thank you");
            }
            else
            {
                VerifyAccess.GenerateMyAccessCode(iUserId, "yourname@domain.com", Request.UserHostName);
                if (VerifyAccess.RecordAffected > 0)
                {
                    //- Send the Code via email to the valid user trying to login
                    var TheVerificationCode = Session["myapp_accesscode"].ToString();
                    string BODY_VERIFICATION_CODE_CONTENT = "<p style='font-size: 14pt; font-weight: bold' align='left'>Your Verification code: " + TheVerificationCode + "</p>";
                    BODY_VERIFICATION_CODE_CONTENT += "<p style='font-size: 10pt;' align='left'><a href'https://www.yoursite.com/Verify.aspx'>https://www.yoursite.com/Verify.aspx</a></p>";

                    //- Send the Verification Code to the user on file via email here

                    Response.Redirect("Verify.aspx");
                }
            }
        }
    }
}
 
 
Verify.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Verify.aspx.cs" Inherits="Verify" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <p>It appears that your device has not been verified.</p>
        <asp:TextBox ID="txtAccessCodeToVerify" runat="server"></asp:TextBox>
        <asp:Button ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" runat="server" />
    </div>
    </form>
</body>
</html>
Verify.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetstairAccessVerifyer; //- Assembly(NetstairAccessVerifyer.ddl) must be present in the bin folder

public partial class Verify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (this.txtAccessCodeToVerify.Text.Trim().Length > 0)
        {   
            //---if (Session["myapp_accesscode"].ToString() == this.txtAccessCodeToVerify.Text.Trim())
            if (VerifyAccess.IsValidVerificationAccessCode(this.txtAccessCodeToVerify.Text.Trim()))
            {
                Response.Redirect("~/Login.aspx");
            }
        }
        else
        {
            Response.Write("<script>alert('Please enter the valid code, sent to your email.');</script>");
        }        
    }    
}
Download Sample here --> Netstair Access Verifier 

Add Feedback