Wednesday, April 15, 2015

How to get MAC Address using java Script Asp.net c#



How to get MAC Address using java Script Asp.net c#

Note : This will work in IE only not for other browsers
.
Steps to Enable Active X in the IE

Click Tools --> Internet Options --> In Security Tab --> Click Trusted Sites --> Insecurity Level of zone 
Disable the (Enable Protected Mode) --> Click Custom Level Button --> Enable the (Initialize and script ActiveX control not marked as safe for scripting  )

<script type="text/javascript">

$(document).ready(function () {
           

            alert(GetMacAddress());
           
            function GetMacAddress() {
                //This function requires following option to be enabled without prompting
                //In Internet Options for IE 5.5 Minimum & Max to latest  and up
                //Tab Security (Local Internet Sites)
                //Custom Level button
                //"Initialize and script ActiveX control not marked as safe." option enabled
                try {
                    var locator = new ActiveXObject("WbemScripting.SWbemLocator");
                    var service = locator.ConnectServer(".");

                    //Get properties of the network devices with an active IP address
                    var properties = service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration" +
                    " WHERE IPEnabled=TRUE");

                    var e = new Enumerator(properties);

                    //Take first item from the list and return MACAddress
                    var p = e.item(0);
                   var s = e.item();
            macAddress = s.MACAddress;
            ipAddress = s.IPAddress(0);
            computerName = s.DNSHostName;
            alert("macAddress= " + macAddress + " ipAddress = " + ipAddress + " computerName = " + computerName)
                }
                catch (exception) {
                    alert('Add your domain to Trusted Sites.');
                    window.location = "about:blank";
                }

                return p.MACAddress;
            }
        });
</script>
Read More »

Tuesday, March 24, 2015

How to view the image while mouse hover using JQUERY in Asp.net C#

How to view the image while mouse hover using JQUERY in Asp.net C#

Step1:- Create one HTML design in the ASPX page

<div id="pop1" class="popbox">
   <asp:Image ID="imghover" runat="server" Width="800px" Height="400px" />
</div>
<a href="#" class="popper" data-popbox="pop1" id="hrfViewImage" runat="server" visible="false">View Image</a>

To assign the Image URL in code View use run at server for HTML Control

Step2:- Assign the image URL in Code View
imghover.ImageUrl = "../Images/Sample.jpg ";

Read More »

How to implement the single user for single login and single session in asp.net c#

How to implement the single user for single login and single session in asp.net c#

Description: In this post I want to explain how to restrict the users to login the application with one session for one login.

Example:-If one user login the application then restrict the user to login with same credentials until the session completes.

Step 1:- Create these methods
///<Authour> ANNAM LOKESH </Authour>
/// <summary>
/// Creating the single session creation using this method
/// </summary>
/// <param name="userID">User Id</param>
/// <param name="password">User password</param>
private void SingleSession(string userID, string password)
{
    Hashtable sessions = (Hashtable)Application["WEB_SESSIONS_OBJECT"];
    if (sessions == null)
    {
        sessions = new Hashtable();
        Response.Redirect("~/Home.aspx", false);
    }
    else
    {
        //check the user in the session
        if (!sessions.ContainsKey(userID))
        {
            //putting the user in the session
            sessions[userID] = userID;
            sessions[userID] = Session;
            Response.Redirect("~/Home.aspx", false);
           
        }
        else
        {
            lblError.Visible = true;
            lblError.Text = "Already Logined with LoginID/Password";
            txtCodeValidate.Text = string.Empty;
        }
    }

    //getting the pointer to the Session of the current logged in user
    HttpSessionState existingUserSession = (HttpSessionState)sessions[userID];
    if (existingUserSession != null)
    {
        existingUserSession[userID] = null;
        //logout current logged in user
    }
    //putting the user in the session
    Session[userID] = userID;
    sessions[userID] = Session;
    Application.Lock(); //lock to prevent duplicate objects
    Application["WEB_SESSIONS_OBJECT"] = sessions;
    Application.UnLock();
}
///<Authour> ANNAM LOKESH </Authour>
/// <summary>
/// Session Clearing Method using the login id
/// </summary>
/// <param name="userID"></param>
private void SingleSessionLogOut(string userID)
{
    //put your logout logic here, remove the user object from the session.
    Hashtable sessions = (Hashtable)Application["WEB_SESSIONS_OBJECT"];
    if (sessions == null)
    {
        sessions = new Hashtable();
    }

    Session.Abandon();
    sessions.Remove(userID);

    Application.Lock();
    Application["WEB_SESSIONS_OBJECT"] = sessions;
    Application.UnLock();
}

Read More »

How to get the list of Active Directory in the System windows c# .net

How to get the list of Active Directory in the System windows c# .net

public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();

            Domain domain = null;
            DomainController domainController = null;
            try
            {
                domain = Domain.GetCurrentDomain();
                DomainName = domain.Name;
                domainController = domain.PdcRoleOwner;
                DomainControllerName = domainController.Name.Split('.')[0];
                ComputerName = Environment.MachineName;
            }
            finally
            {
                if (domain != null)
                    domain.Dispose();
                if (domainController != null)
                    domainController.Dispose();
            }
        }

        public static string DomainControllerName { get; private set; }

        public static string ComputerName { get; private set; }

        public static string DomainName { get; private set; }

        public static string DomainPath
        {
            get
            {
                bool bFirst = true;
                StringBuilder sbReturn = new StringBuilder(200);
                string[] strlstDc = DomainName.Split('.');
                foreach (string strDc in strlstDc)
                {
                    if (bFirst)
                    {
                        sbReturn.Append("DC=");
                        bFirst = false;
                    }
                    else
                        sbReturn.Append(",DC=");

                    sbReturn.Append(strDc);
                }
                return sbReturn.ToString();
            }
        }

        public static string RootPath
        {
            get
            {
                return string.Format("LDAP://{0}/{1}", DomainName, DomainPath);
            }
        }

    }
Read More »