Professional Documents
Culture Documents
SOFTMATIC
COACHING
CLASSES
InProc:- In this mode Session state is stored in the memory space of the Aspnet_wp.exe
process. This is the default setting. If the IIS reboots or web application restarts then session
state is lost.
StateServer:- In this mode Session state is serialized and stored in a separate process
(Aspnet_state.exe); therefore, the state can be stored on a separate computer(a state server).
SQL SERVER:- In this mode Session state is serialized and stored in a SQL Server
database.
Session state can be specified in <sessionState> element of application configuration file. Using
State Server and SQL SERVER session state can be shared across web farms but note this comes
at speed cost as ASP.NET needs to serialize and deserialize data over network again and again.
<sessionState mode=SQLServer
stateConnectionString=tcpip=192.168.1.1:42424"
sqlConnectionString=data source=192.168.1.1; Integrated Security=SSPI
cookieless=false
timeout=20"
/>
Above is sample session state mode specified for SQL SERVER.
Other than session variables you can use the following technique to store state :
Hidden fields
View state
Hidden frames
Cookies
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
Query strings
Page performance decreases if you store large data, as the data are stored in pages itself.
Hidden fields do not support rich structures as HTML hidden fields are only single valued.
Then you have to work around with delimiters etc to handle complex structures.
Below is how you will actually implement hidden field in a project
<input id="HiddenValue" type="hidden" value="Initial Value"
runat="server"NAME="HiddenValue">
What is ViewState ?
Viewstate is a built-in structure for automatically retaining values amongst the multiple requests
for the same page. The viewstate is internally maintained as a hidden field on the page but is
hashed, providing greater security than developer-implemented hidden fields do.
Performance of viewstate varies depending on the type of server control to which it is applied.
Label, TextBox, CheckBox, RadioButton, and HyperLink are server controls that perform well
with ViewState. DropDownList, ListBox, DataGrid, and DataList suffer from poor performance
because of their size and the large amounts of data making roundtrips to the server.
What are benefits and Limitation of using Viewstate for state management?
No server resources are required because state is in a structure in the page code.
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
Simplicity.
The values in view state are hashed, compressed, and encoded, thus representing a higher
state of security than hidden fields.
View state is good for caching data in Web frame configurations because the data is cached
on the client.
Following are limitation of using Viewstate:
Page loading and posting performance decreases when large values are stored because view
state is stored in the page.
Although view state stores data in a hashed format, it can still be tampered
because it is stored in a hidden field on the page. The information in the hidden field can also be
seen if the page output source is viewed directly, creating a potential security risk.
Below is sample of storing values in view state.
this.ViewState["EnterTime"] = DateTime.Now.ToString();
This technique is implemented by creating a Hidden frame in page which will contain your data
to be cached.
<FRAMESET cols="100%,*,*">
<FRAMESET rows="100%">
<FRAME src="data_of_frame1.html"></FRAMESET>
<FRAME src="data_of_hidden_frame.html">
<FRAME src="data_of_hidden_frame.html" frameborder="0" noresize
scrolling="yes">
</FRAMESET>
Above is a sample of hidden frames where the first frame data_of_frame1.html is visible and
the remaining frames are hidden by giving whole col section to first frame. See allocation where
100 % is allocated to first frame and remaining frames thus remain hidden.
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
The ability to cache and access data items stored in different hidden forms.
The ability to access JScript variable values stored in different frames if they come
from the same site.
The limitations of using hidden frames are:
Some users disable their browser or client devices ability to receive cookies, thereby
limiting the use of cookies.
What is Query String and What are benefits and limitations of using Query Strings?
A query string is information sent to the server appended to the end of a page URL.
Following are the benefits of using query string for state management:Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
No server resources are required. The query string containing in the HTTP requests for
a specific URL.
Following are limitations of query string : Query string data is directly visible to user thus leading to security problems. Most browsers and client devices impose a 255-character limit on URL length.
Below is a sample Login query string passed in URL http://www.querystring.com/
login.asp?login=testing. This query string data can then be requested later by using
Request.QueryString(login).
Absolute Expiration allows you to specify the duration of the cache, starting from the time
the cache is activated. The following example shows that the cache has a cache dependency
specified, as well as an expiration time of one minute.
Cache.Insert("announcement", announcement, depends, _
DateTime.Now.AddMinutes(1), Nothing)
Sliding Expiration specifies that the cache will expire if a request is not made within a
specified duration. Sliding expiration policy is useful whenever you have a large number of
items that need to be cached, because this policy enables you to keep only the most
frequently accessed items in memory. For example, the following code specifies that the
cache will have a sliding duration of one minute. If a request is made 59 seconds after the
cache is accessed, the validity of the cache would be reset to another minute:
Cache.Insert("announcement", announcement, depends, _
DateTime.MaxValue, _
TimeSpan.FromMinutes(1))
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
By default, button controls in ASP.NET pages post back to the same page that contains
the button, where you can write an event handler for the post. In most cases this is the
desired behavior, but occasionaly you will also want to be able to post to another page in
your application. The Server.Transfer method can be used to move between pages,
however the URL doesn't change. Instead, the cross page posting feature in ASP.NET 2.0
allows you to fire a normal post back to a different page in the application. In the target
page, you can then access the values of server controls in the source page that initiated
the post back.
To use cross page posting, you can set the PostBackUrl property of a Button, LinkButton
or ImageButton control, which specifies the target page. In the target page, you can then
access the PreviousPage property to retrieve values from the source page. By default, the
PreviousPage property is of type Page, so you must access controls using the FindControl
method. You can also enable strongly-typed access to the source page by setting the
@PreviousPageType directive in the target page to the virtual path or Type name of the
source page.
Here is a step-by-step guide for implementing the cross-page post back using controls
that implement the IButtonControl interface.
Create a Web Form and insert a Button control on it using the VS .NET designer.
Set the button's PostBackUrl property to the Web Form you want to post back. For
instance in this case it is "nextpage.aspx"
<asp:Button ID="Button1" runat="server"
PostBackUrl="~/nextpage.aspx" Text="Post to nextpage" />
When the PostBackUrl property of the IButtonControl is set, the ASP.NET framework
binds the corresponding HTML element to new JavaScript function named
WebForm_DoPostBackWithOptions. The corresponding HTML rendered by the
ASP.NET 2.0 will look like this:
<input type="submit" name="Button1" value="Post to Page 2"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("Button1", ",false,"Page2.aspx", false, false))"
id="Button1" />
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070
state information of the poster page. To access the view state of the poster page, you can
use the new PreviousPage property of the page:
Page poster = this.PreviousPage;
Then you can find any control from the previous page and read its state:
Label posterLabel = poster.findControl("myLabel");
String lbl = posterLabel.Text;
This cross-page post back feature also solves the problem of posting a Form to multiple
pages, because each control, in theory, can point to different post back URL.
Contact : Somnath Heights, Above Swati Printing Press , Opp. D-Mart, Kalewadi,Pune
Mob : 8855947070