Hi Shitalsurv,
Check this example. Now please take its reference and correct your code.
When user inserts url in the TextBox and click on the send Button, email will be sent to the user with the link.
When receiver click in the link the LinkTrack.aspx page gets called and based on the QueryString value data is saved in the database table LinkRedirects.
Now you will be able to get the count of link clicked as per your need.
Database
I have made use of the following table LinkRedirects with the schema as follows.
CREATE TABLE LinkRedirects(ID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID())
CS.aspx
<asp:TextBox runat="server" ID="txtUrl" />
<asp:Button Text="Send" ID="btnSend" runat="server" OnClick="Send" />
CS.aspx.cs
protected void Send(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage("sender@gmail.com", "receiver@gmail.com"))
{
Guid id = Guid.NewGuid();
string url = Server.UrlEncode(txtUrl.Text.Trim());
mm.Subject = "Link";
string body = "Hi,";
// url will be fully qualified url of running application.
body += "<br /><br />Click this <a href = 'LinkTrack.aspx?ID=" + id + "&url=" + url + "'>link</a>";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("sender@gmail.com", "<password>");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
LinkTrack.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
string id = Request.QueryString["ID"];
string url = Request.QueryString["Url"];
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO LinkRedirects VALUES(@Id)";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect(Server.UrlDecode(url));
}
}
Screenshot