Friday 28 March 2014

get IP address from client machine





public string GetIPAddress()
    {
        System.Web.HttpContext context = System.Web.HttpContext.Current;
        string MyIP = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        if (!string.IsNullOrEmpty(MyIP))
        {
            string[] addresses = MyIP.Split(',');
            if (addresses.Length != 0)
            {
                return addresses[0];
            }
        }
        return context.Request.ServerVariables["REMOTE_ADDR"];
    }


//And You can calll this method as following where you want get the IP Client Address

string ip = GetMyIPAddress();

upload or publish web-site


auto complete search texbox fill name with image


multiple select option for delete option in gridview


confirmation message when delete data from All datacontrol


find control Id from all data control in asp.net


previous page will not back after log-out

--> When you logged out successfully and click on browser's back button then it should not be come back again in your home page.
--> It means previous page will not back after log-out
--> The following code is for previous page will not back after log-out

Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

It's solution for

 

Browser Back Button Issue After Logout
Back Button issue after Logout in ASP.NET
Avoid go back after Logout
prevent go back after logout


Following code is use in Page_Load() method of your Home page or Master page.


public void RemoveCache()
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
        Response.Cache.SetNoStore();
    }

Log-out code in asp.net with C#

The following code is for log out

Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

Use following code for log out and redirect in log-in page.


public void LogOutCode()
    {
        Session.Abandon();
        Session.Clear();
        Session.Remove("SessioName");

        Response.Redirect("~/Log-in.aspx");
    }

fill data from database using javascript code without page refresh


css file change runtime in asp.net


file update or delete in asp.net

--> The following code is for delete file using C# code.
--> If you want to delete file using Asp.net then use following code on your code behind file


Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------

Your .aspx file should be like this


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="lblStatus" runat="server" />
            <br />
           <asp:Button Text="Delete File" ID="btnDeleteFile" runat="server" OnClick="btnDeleteFile_Click" />
        </div>
    </form>
</body>
</html>


And your code behind file should be like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDeleteFile_Click(object sender, EventArgs e)
    {
        string FileName = "here-my-file-name";
        string YourPath = Server.MapPath("FolderName") + "\\" + FileName;
        FileInfo GetMyFile = new FileInfo(YourPath);
        if (GetMyFile.Exists)
        {
            GetMyFile.Delete();
            lblStatus.Text = "File is Deleted";
        }
        else
        {
            lblStatus.Text = "File is not Delete";
        }
    }
}


Asp.net tutorials