Wednesday 23 April 2014

ASP.NET Cache


One of the most important factors in building high-performance, scalable Web applications is the ability to store items, whether data objects, pages, or parts of a page, in memory the initial time they are requested. You can cache, or store, these items on the Web server or other software in the request stream, such as the proxy server or browser. This allows you to avoid recreating information that satisfied a previous request, particularly information that demands significant processor time or other resources. ASP.NET caching allows you to use a number of techniques to store page output or application data across HTTP requests and reuse it.

ASP.NET provides two types of caching that you can use to create high-performance Web applications.

The first is output caching, which allows you to store dynamic page and user control responses on any HTTP 1.1 cache-capable device in the output stream, from the originating server to the requesting browser. On subsequent requests, the page or user control code is not executed; the cached output is used to satisfy the request.
he second type of caching is application data caching, which you can use to programmatically store arbitrary objects, such as application data, in server memory so that your application can save the time and resources it takes to recreate them.

sending email along with database values as attachment in c#

try
    {
      byte[] bytes;
      MailMessage email = new MailMessage();

      email.From = new MailAddress("<sourcr email address>");
      email.To.Add("<destination email address>");
      email.Subject = "Mail Testing";
      email.Body = "You are Successfully Created Profile......";
      string constr =         ConfigurationManager.ConnectionStrings["fishbowlConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand())
                {                  
                    cmd.CommandText = "SELECT UserName FROM Email";
                    cmd.Connection = con;
                    con.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {                      
                        sdr.Read();
                        bytes =         Encoding.ASCII.GetBytes(sdr["UserName"].ToString());                       
                        MemoryStream pdf = new MemoryStream(bytes);
                        Attachment data = new Attachment(pdf, "example.txt", "text/plain");
                        email.Attachments.Add(data);
                    }
                    con.Close();
                }
            }
            SmtpClient smtp = new SmtpClient();
            smtp.UseDefaultCredentials = false;

            smtp.Credentials = new System.Net.NetworkCredential("<source email address>", "<source email password>");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.Send(email);
        }
        catch (Exception Ex)
        {
            Console.WriteLine(Ex.ToString());
        }