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 »

How to get IP Address of Visitors Machine || Client Machine in ASP.Net

Description: -This post explains you to know how to get the client IP Address from ASP.Net c#
C#
string ipaddress;
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (ipaddress == "" || ipaddress == null)
    ipaddress = Request.ServerVariables["REMOTE_ADDR"];

When users are behind any proxies or routers the REMOTE_ADDR returns the IP Address of the router and not the client user’s machine. Hence first we need to checkHTTP_X_FORWARDED_FOR, since when client user is behind a proxy server his machine’s IP Address the Proxy Server’s IP Address is appended to the client machine’s IP Address. If there are multiple proxy servers the IP Addresses of all of them are appended to the client machine IP Address.
Hence we need to first check HTTP_X_FORWARDED_FOR and then REMOTE_ADDR.

Your IP Address like …………
192.658.55.36
Note: - While executing this code it will show the wrong IP Address in local development in some case. After deploy in IIS it will show the correct address.


Read More »

How to create the Capture Image || Login Image authentication creation in asp.net c#

How to create the Capture Image || Login Image authentication creation in asp.net c#

Step 1:- Create one asp page and name it as CaptureImage.aspx

In .CS file write below code
namespace IDMSUI
{
    public partial class CaptureImage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetCaptureImage();
        }
        public void GetCaptureImage()
        {
            using (Bitmap b = new Bitmap(150, 40, PixelFormat.Format32bppArgb))
            {
                using (Graphics g = Graphics.FromImage(b))
                {
                    Rectangle rect = new Rectangle(0, 0, 149, 39);
                    //Rectangle rect = new Rectangle(0, 0, 100, 25);
                    g.FillRectangle(Brushes.White, rect);

                    // Create string to draw.
                    Random r = new Random();
                    int startIndex = r.Next(1, 5);
                    int length = r.Next(5, 10);
                    String drawString = Guid.NewGuid().ToString().Replace("-", "0").Substring(startIndex, length);
                    Session["CaptureImageCode"] = drawString;
                    // Create font and brush.
                    Font drawFont = new Font("Arial", 16, FontStyle.Italic);
                    //Font drawFont = new Font("Arial", 16, FontStyle.Italic | FontStyle.Strikeout);
                    //Font drawFont = new Font("Arial", 16, FontStyle.Italic);
                    using (SolidBrush drawBrush = new SolidBrush(Color.Black))
                    {
                        // Create point for upper-left corner of drawing.
                        PointF drawPoint = new PointF(15, 10);

                        // Draw string to screen.
                        g.DrawRectangle(new Pen(Color.Red, 0), rect);
                        g.DrawString(drawString, drawFont, drawBrush, drawPoint);
                    }
                    //b.Save(context.Response.OutputStream, ImageFormat.Jpeg);
                    //context.Response.ContentType = "image/jpeg";
                    //context.Response.End();
                    this.Response.Clear();
                    this.Response.ContentType = "image/jpeg";
                    // Write the image to the response stream in JPEG format.
                    b.Save(this.Response.OutputStream, ImageFormat.Jpeg);
                    // Dispose of the CAPTCHA image object.
                    b.Dispose();
                }
            }
        }
    }
}

Read More »