Pages

Ads 468x60px

For New Update Use this Link http://dotnethubs.blogspot.in/ Offer for you

.

Showing posts with label query string. Show all posts
Showing posts with label query string. Show all posts

Monday 15 April 2013

Difference Between Query String and Session and Cookies


Difference Between Query String and Session and Cookies
Querystring Session
Querystring is client side state management technique. Session is server side state management technique.
Querystring data is page specific i.e. can be accessed in that page only. Session data can be accessed throughout the session.
Querystring data is visible to user and can be seen in browser url. Session data is not visible to user.
Data is not secured and can be altered hence insensitive data is stored in querystring. Data is secured hence sensitive data such as user information is stored.
Querystring has constraint of Maxlength. Session does not have such constraint.

Difference between Query string and Cookies

cookies is a text file stored on client machine when we surf ant thing on internet by the server automatically we dont have to create it

query string is used to transfer data from 1 page to anothe but this is not safe s it shows in url what data we r sending
pen any site and see url after question mark tht is url

Cookies: - Cookies are little pieces of information that a server stores on a browser. They are of two types
1. Temporary cookie
2. Persistent cookie

Temporary cookie: - They are also known as session cookies. These are volatile in nature. When the browser is shutdown they are erased.

Persistent cookie:- These may be called as permanent cookies. These are especially saved in files. It may remain for a month or year.

Properties of cookies
Some properties of cookie
Name: - represent the name of cookie.
Name value: - represent a collection of key values of cookie
Domain: - represent the domain associated with a specific cookie.
Path: - the path associated with a cookie.
Expires: - expired time of cookie.
Hashkey: - identifies whether the cookie is a cookie dictionary.
Secure: - specifies whether the cookie is to be sent in an encrypted connection or not


Query string is the limited way to pass information to the web server while Transferring from one page to another page. This information is passed in url of the request. see below the code sample


Code Sample

//Retrieving values from query string
String name;
//Retrieving from query string
name = Request.Param["umar"].ToString();

But remember that many browsers impose a limit of 255 characters in query strings. You need to use HTTP-Get method to post a page to server otherwise query string values will not be available.

Difference between Session and Cookies

The basic and main difference between cookie and session is that cookies are stored in the user's browser but sessions can't store in user's browser. This specifies which is best used for.

• A cookie can keep all the information in the client's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie.

• Sessions are not reliant on the user allowing a cookie. They work like a token in the browser which allowing access and passing information while the user has opened his browser. The problem in sessions is when you close the browser the session will automatically lost. So, if you had a site requiring a login, this couldn't be saved as a session but it can be saved as a cookie, and the user has to re-login every time they visit.

Monday 1 April 2013

query string in asp.net

query string in asp.net

Introduction:

The QueryString collection is used to retrieve the variable values in the HTTP query string.
The HTTP query string is specified by the values following the question mark (?),
 like this:
http://localhost:2525/QueryString/getquerystring.aspx?name=rahul&password=123.
 Query strings are included in bookmarks and in URLs that you pass in an e-mail. They are the only way to save a page state when copying and pasting a URL.

Description:


Now I have one page which contains one textbox and button control I need to send textbox value to another page when we click on button control for that we need to write the code like this
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("getquerystring.aspx?name="+this.txt_nm.Text);
}
Or
In case if we need to send multiple parameters to another page we need to write code like this
protected void btnSend_Click(object sender, EventArgs e)
{
Response.Redirect("getquerystring.aspx?name="+this.txt_nm.Text+"&password="+this.txt_pass.Text);
}
Now we need to get these values in another page (here I mentioned Default2.aspx) by using QueryString Parameter values with variable names or index values that would be like this
protected void Page_Load(object sender, EventArgs e)
{

string name = Request.QueryString["name"];
string password = Request.QueryString["password"];

}

first create new website and open Default.aspx page and write the following code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>QueryString Example in asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div><b>QueryString Example</b></div><br />
<div>
<table>
<tr>
<td><b>Enter the Name:</b></td>
<td><asp:TextBox ID="txt_nm" runat="server"/></td>
</tr>
<tr>
<td><b>Enter the Password</b></td>
<td><asp:TextBox ID="txt_pass" runat="server"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="Button1" runat="server" onclick="Button1_Click"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
After that write the following code in code behind
protected void btnSend_Click(object sender, EventArgs e)
{
Response.Redirect("getquerystring.aspx?name="+txt_nm.Text+"&pasword="+txt_pass.Text);
}
Now Right click on your website and Add New item and add new page (getquerystring.aspx) open that getquerystring.aspx page and write the following code
On  code behind
protected void Page_Load(object sender, EventArgs e)
{

 string name = Request.QueryString["name"];
 string password = Request.QueryString["password"];
Response.Write("name=" + name + "\t" + "password=" + pasword);
}

Example



Download sample code attached



 

..




New Updates

Related Posts Plugin for WordPress, Blogger...

Related Result