Asp.Net Trainning Notes - 2

 

* State Management 

* Web Service 

* Hosting

* Master Page

* Jquery

File Upload - https://www.c-sharpcorner.com/article/Asp-Net-2-0-fileupload-control/

MasterPage - https://www.c-sharpcorner.com/article/how-to-create-master-page-in-asp-net/


State , cookie , session, redirect C:\Users\vasan\source\repos\Insert_view_Asp_net\Insert_view_Asp_net



Insert & View From Sp and cookies  -  C:\Users\vasan\source\repos\Insert_view_Asp_net


CREATE TABLE [StudentTest](

[id] [int] IDENTITY(1,1)  PRIMARY KEY NOT NULL,

[Fname] [nchar](10) NOT NULL,

[MName] [nchar](10) NULL,

[Lastname] [nchar](10) NULL)

 

Edit some values


Create procedure  [dbo].[studentEntryView1]    

(    

@Action varchar (10),    

@fname Varchar (50),    

@Mname varchar (50),    

@Lname Varchar (50)    

)    

as    

begin    

If @Action='Insert'   --used to insert records    

Begin    

Insert into Student1 (Fname,MName,Lastname) values (@fname,@Mname,@Lname)    

End    

else if @Action='View'   --used to view records    

Begin    

select *from Student1     

End    

End 


Types of State Management in ASP.NET 

There are two types of State management in ASP net. They are :

  • Server-side 
  • Client-side

These are further subdivided into the following -

Server-Side

  • Session
  • Application
  • Cache

Client-Side

  • Cookies 
  • Query String
  • Hidden Field 

Server-Side of State Management in ASP NET

Session 

An important technique to maintain state. It is used to store identity and information; information is stored in the server using Sessionid.

To start the user session -

Example

protected void btnSubmit_Click(object sender, EventArgs e)  

{  

   Session["UserName"] = txtName.Text;  

   Response.Redirect("Home.aspx");  

}  


Two types -

Session starts - Raised every time a new user requests without a session ID.

Example

void Session_Start(object sender, EventArgs e)  

{  

   Session["Master"] = "~/Master.master";  

}  

Session end - Raised everytime the user ends the session or a time out occurs.

Example

void Session_End(object sender, EventArgs e)  

{  

   Response.Write("Session_End");  

}  

The session is stored in the following ways in ASP.NET:

InProcMode - Default session mode. When the server starts, the session value is stored, and when the server is restarted, it ends.

State Server Mode - Session date is made to store on a separate server in this mode.

SQL Server Mode - It’s a secure mode in which the session is made to store in the database.

Custom Mode - Session data is generally stored in InProcMode, SQL Server Mode, etc. In case we want to store using any other techniques, we use the custom mode.

Application

It is a server-side management state and is also known as the application level state management. This is mainly used to store user activity in server memory and application events.

This is further classified into three types :

Application start - The event begins with the start of the domain.

Example 

Void ApplicationStart(object sender, EventArgs e)  

{  

   Application["ApplicationstartMessage"] = "Welcome to Simplilearn";  

}  

Application error - This is used to manage/handle an error or exception that had been previously unhandled.

Example

void ApplicationError(object sender, EventArgs e)   

{   

   // Unhandled exception code block 

}

Application end - Whenever the domain ends, this ends as well.

Example 

Void ApplicationEnd(object sender, EventArgs e)  

{  

   Application["ApplicationEndMessage"] = "Applications are Closed";  

}

Cache

This is stored on the server-side, and it is used to implement page caching and data caching. A cache is primarily used to set expiration policies.

Example snippet

Response.Cache.SetExpiresTime(DateTime.Now.AddDays(1));

Client-Side State Management in ASP.NET

There are four main parts of State Management on the Client Side -

Cookie

One of the smallest but important parts of the ASP NET, it is used to store the session and application information of the user. It can be constant and temporary and works with browser requests. The server can read these cookies from the client-side and perform data abstraction. 

There are two types of cookies that are available -

Persistence - The Persistence cookie works along with Time and Date.

Example 

Response.Cookies["CookiesName"].Value = "Testing Cookies";  

//setting the expire time

Response.Cookies["CookiesName"].Expires = DateTime.Today.AddHours(2);  

Non-Persistence - Temporary cookie created with application access and closed application is discarded.

Example 

Response.Cookies["CookiesName"].Value = "Testing Cookies";  

Hidden Field

This field is used to store values on the client-side. The hidden field works on request and is not displayed on the browser.

Example 

if (HiddenField.Value != null)  

{  

   int dat = Convert.ToInt32(HiddenField.Value) + 1;  

   HiddenField.Value = dat.ToString();  

   Labels.Text = dat.ToString();  

Query String

The query string is used to store the value in the URL.

Example 

Response.Redirect("ShowStringValue.aspx?Username=" + txtUsername.Text);





What is a Cookie?

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With ASP, you can both create and retrieve cookie values.



Comments

Popular Posts