Saturday, September 16, 2023

SERVER SIDE WEB CONFIG FILE CONNECTION STRING

 Web.config  File 


<?xml version="1.0"?>
<configuration>



  <appSettings>


    <add key="keyname" value="Data Source=ipaddress;

                              Network Library=DBMSSOCN;

                              Connection Timeout=15;

                              Packet Size=4096;

                              Integrated Security=no;

                               Initial Catalog=databasename;

                               User ID=username;

                               password=password;

                               Encrypt=no;

                               Max Pool Size=50000;"/>

  </appSettings>

<system.web>

            <customErrors mode="Off"/>

<compilation debug="true" targetFramework="4.0"/>

</system.web>

</configuration>



======================================================================

How to access Config  File 

using System.Configuration;

 SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["keyname"]);

con.Open();





FILE UPLOAD CONCEPT IN SERVER SIDE FOLDER

  protected void Button1_Click(object sender, EventArgs e)

    {

        FileUpload1.SaveAs(Server.MapPath(@"~/batch23/nilesh/") + "//upload//" + FileUpload1.FileName);


    }




Friday, September 1, 2023

Final Email Programming

 

Email programming

1)    Email is provide a communication between one system to an other system

2)    Types of email-  1.generic mail 2.domain mail

Generic mail:- it is a common mail (yahoo, gmail)all generic mail

Domain mail:-it representing to company/organization mail(contact@tcs.com,info@hcl.com )etc

 

How to use email programming in .net framework

There are following step is used to communicate email in .net framework

Step1.include email library. (using system.net.mail)

Step2. Create email object 1)mailmessage object 

Step3. Verify your mail id (change password or two steps verification )


Verify Your Gmail Account 

            àgo to your gmail accountàclick on manage your google accountàclick on securityàHow you sign in to Googleà2 step verificationàverify by entering your correct passwordàenter on app passwordat at the bottom of pageàselect app(other(custome name))enter name of app like asp.netàclick on generate buttonàthere will be generate 16 digit code àcopy that code and use in the program on the place of mail passwordàrun the program

 


using System.Net.Mail;

        MailMessage msg = new MailMessage();

        SmtpClient smtp1 = new SmtpClient();

        //how to use mailmessage object

        msg.To.Add(TextBox1.Text);

        msg.From=new MailAddress("abc@gmail.com");//your mail id

        msg.Subject = "this is testing mail";

        msg.Body = "dear user thanks for visit my website";

        //how to set html formate

        msg.IsBodyHtml = true;


             

        //how to use smtp object  ..set host(server)gmail.com, yahoo.com etc

        smtp1.Host = "smtp.gmail.com";

        smtp1.port=587

        //hset the credentials

        smtp1.Credentials = new System.Net.NetworkCredential("abc@gmail.com"

         "xxxtvxbkfvggthgr");

        //enable sss certificate

        smtp1.EnableSsl = true;//(only work https domain)

        //send mail using smtp object

        smtp1.Send(msg);//pass mailmessage object


https://www.google.com/settings/security/lesssecureapps


Domain Mail concept 


SmtpClient smtpClient = new SmtpClient("nrsolution4u-student.com", 587);//outgoing port 587, incoming port 110

 

        smtpClient.Credentials = new System.Net.NetworkCredential("contact@nrsolution4u-student.com", "password");

        smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

       // smtpClient.EnableSsl = true;

 

        MailMessage mailMessage = new MailMessage("contact@nrsolution4u-student.com", TextBox1.Text.Trim());

        mailMessage.Subject = "Domain Testing";

        mailMessage.Body = "this is domain mail testing";

 

 

        mailMessage.IsBodyHtml = true;

        smtpClient.Send(mailMessage);

        Label1.Text = "email send successfully";






Thursday, August 17, 2023

Application state , View State , Cookies

 


ASP.Net Application State

ASP.Net Application state is a server side state management technique.Application state is a global storage mechanism that used to stored data on the server and shared for all users, means data stored in Application state is common for all user. Data from Application state can be accessible anywhere in the application. Application state is based on the System.Web.HttpApplicationState class.

 

Syntax of Application State

Create  application state

·         Application[“varible”] = control;

Retrieve information from application state

·         Control = Application[“varible”].ToString();

 

Example of Application State in ASP.Net

Generally we use application state for calculate how many times a given page has been visited by various clients.

 

 

Coading  for button_click  event

 

protected void button_Click(object sender, EventArgs e)

    {

        int count = 0;

 

        if (Application["Visit"] != null)

        {

            count = int.Parse(Application["Visit"].ToString());

        }

 

        count = count + 1;

        Application["Visit"] = count;

        Label1.Text = "Total Visit = " + count.ToString();

       

    }

 

 

 

 

 

 

Run Program

1.    Run  program

2.    Copy URL 

3.    Past URL  to  new  tab  on browser

Result

Label show  number of count to visit  user

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ViewState Example in ASP.Net

ViewState is a important client side state management technique. ViewState is used to store user data on page at the time of post back of web page.

ViewState does not hold the controls, it holds the values of controls. It does not restore the value to control after page post back. ViewState can hold the value on single web page, if we go to other page using response.redirect then ViewState will be null.

 

·         ViewState stores data on single page

·         ViewState is client side state management technique

·         Session stores data on whole website pages

·         Session is a server side state management technique

 

Viewstate Example

Store the value in viewstate

ViewState[“varible”]=control;

 

Retrieve information from viewstate

control=ViewState[“varible”].ToString();

 

 

C# Code for above example

 protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnclear_Click(object sender, EventArgs e)
    {
        ViewState["name"] = TextBox1.Text;
        
         TextBox1.Text = "";
    }
    protected void btndisplay_Click(object sender, EventArgs e)
    {
        Label1.Text = ViewState["name"].ToString();
    }

 

 

 

Run Program

1.  First write any data in textbox

2.   After that click clear value button

3.   After that click  display value button

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

ASP.Net Cookie Example

Cookies is a small pieces of text information which is stored on user hard drive using users browser for identify users. It may contain username, ID, password or any information. Cookie does not use server memory.

 

How  to create Cookies

Response.Cookies["varible"].Value = control;

 

 

 

How  to expire  cookies

 

Response.Cookies["varible"].Expires= DateTime.Now.AddMinutes(1);

 

 

C# code for Cookie Example

Create Cookie Button C# Code

protected void btncreate_Click(object sender, EventArgs e)
    {
       Response.Cookies["name"].Value = Textbox1.Text;
       Response.Cookies["name"].Expires = DateTime.Now.AddMinutes(1);
       Label1.Text = "Cookie Created";
       Textbox1.Text = "";
    }   

 

 

 

 

Retrieve Cookie Button Code

protected void btnretrieve_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["name"] == null)
        {
            Textbox2.Text = "No cookie found";
        }
        else
        {
            Textbox2.Text = Request.Cookies["name"].Value;
        }
    }

 

 

 

 

SERVER SIDE WEB CONFIG FILE CONNECTION STRING

  Web.config  File  <?xml version="1.0"?> <configuration>   <appSettings>     <add key="keyname" va...