Difference between Session and Cookies



Sessions
It is used to store user information in server memory. Usually it stores userid, name etc.. sensitive information stored in session and it will maintain its state when you navigate through a website.  You can store the session information either in cookies or cookieless mode.
If cookieless = false, session value stored in cookies, if it true it will be stored in the browser URL. but if you copy the URL and paste in another tab of  the same browser the session will be expired.

You can store the session in three modes
In-Proc
State server
SQL server

Example 
Session["userName"] = "Ganesh Ram";

if(Session["UserName"] != null)
  lblUserName.Text = Session["UserName"].ToString();
 
Cookies
Cookies are stored per-user on the users machine. A cookie is usually just a bit of information. Cookies are usually used for simple user settings colours preferences etc. No sensitive information should ever be stored in a cookie.
You can never fully trust that a cookie has not been tampered with by a user or outside source however if security is a big concern and you must use cookies then you can either encrypt your cookies or set them to only be transmitted over SSL. A user can clear there cookies at any time or not allow cookies altogether so you cannot count on them being there just because I user has visited your site in the past.

//add a username Cookie
Response.Cookies["UserName"].Value = "Ganesh Ram";
Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(10);

//request a username cookie
if(Request.Cookies["UserName"] != null)
   lblUserName.Text = Server.HtmlEncode(Request.Cookies["UserName"].Value);
 


Difference between Clustered index and Non-Clustered index



Indexing  is way to sort and search records in the table. It will improve the speed of locating and retrieval of records from the table

In SQL there are two types of index.
1. Clustered index
2. Non-Clustered index.

Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index. 

Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db
In SQL 2005
Clustered index - 1 Clustered index
Non-Clustered index - 249 Non-Clustered index
In SQL 2008 
Clustered index - 1 Clustered index
Non-Clustered index - 999 Non-Clustered index 

Example
USE Sample
GO
CREATE TABLE Employee
(ID  bigint PRIMARY KEY CLUSTERED,
Name nvarchar(150),
Address nvarchar(250),
Salary varchar(25) )
GO
CREATE NONCLUSTERED INDEX EmpName ON Employee(Name)
GO


Define Stored procedure ?



It is a collection of transact sql statements that can take or return user supplied parameters.

Maximum size of stored procedure is 128 MB.


Difference between Having and Group By clause ?



Having Clause : To filter the rows from the grouped results

Group By : is used for grouping the operation.

Group by : Ccause  is used to group the output of the WHERE clause..


Define View ?



It is nothing but a virtual table that represent the data in one or more tables in a alternative way.


What is index ?



Index is a pointer in sql server to retrieve the data faster from database.

It’s a physical structure containing pointers to data.

Its created in existing tables to locate rows more quickly and efficiently.

Types of Index:

a)    Clustered Index : It contains only one index ie: Creating a primary key for the table.
Physical sorting of data in the storage media.

b)    Non-Clustered Index :  A table can contains 249 non-clustered index, It can be created outside of the database tables , that contain a sorted list of references to the table itself.


Define Delegates ?



Delegate is  a class that can hold reference to a method or a function .

Delegate class has a signature and it only reference those method whose signature is compliant with the class.

Delegates are type safe , secure , object oriented.


Difference b/w int.Parse and Convert.ToInt32()?



Int.Parse – It can’t handle NULL value.

Convert.ToInt32 – It handles null value and converts value to default value ‘0’.


What is Finalize and Dispose ?



Finalize:  - Automatically done by garbage collector  to clean the resource memory.

Dispose: - Force the user to dispose objects.


Boxing and Unboxing ?



Boxing:

Implicit conversion of any value type to the type object.
Value types are stored on stack.
Reference or object type are stored on heap.

Unboxing:

Explicit conversion from object type to value type.


Reflection ?



You can see the metadata information through reflection mechanism.

Ability to inspect and manipulate programs elements at runtime.

It’s the process of runtime type discovery.

Reflection Services:

Load an assembly at runtime.
Enumerate members of a type.
Instantiate a new object.
Execute the members of an object.
Find out the information about a type .
Find out the information about a assembly
Inspect custome attributes applied to a type.
Create and compile new assembly.


What is Session ?



Session is used to store user details particularly userid and user information so once you set the information  in session you can get the data anywhere in the project .


Syntax:

Session[“username”] = “Venkat”;


How to write stored procedure – give syntax ?



Create Procedue <procedureName>
(
Your parameter
)
As
Begin
< your Sql Statement>
End


To create a new Guid?



Guid getnewID = Guid.NewGuid();


Difference between timestamp and uniqueidentifier ?



TimeStamp:

Size – 8 bytes.
Note based on system date or time
To track the operation in tables on the database level.

Uniqueidentifier

16 – bytes.
Value is based on the computer MAC Addresss and system datetime.
It remains unique in any system in the world.


How to convert from string to GUID ?



String mystring = “xxxx-xxxx-xxxx-xxxx”;

Guid = new Guid(mystring);

Newid() = Globally unique identifier

NewSequentialId() – Globally sequential identifier


Where the session is stored ?



<sessionState  mode =”InProc” cookieless=”False” timeout=”20”/>

By default Cookieless is set to false – so the session Id is stored in Cookies so as long as user navigating the page you can get the session from cookies.

If you set the cookieless =”True” the session id is stored on the browser url before the file name

Ex: http://yourserver/folder/(sessionid)/default.aspx

Drawback is if the user working on the site it has assigned some sessionId on the url  , by giving the different url on Address bar and do some process once the user type same url at that time it will give different sessionid, the previous session will be lost and lost all of previous state.

Default timeout for session is 20 Mins.

Default timeout for Form authentication 30 Mins.


How to display the Name on Email to address



EX:

MailMessage msg = new MailMessage();

Msg.from = new mailAddress(“youraddress@gmail.com”, “Test”);


Form authentication Configuration



<authentication mode=”forms”>
<forms name =”.ASPXAUTH” login url=”login.aspx” protection=”All” timeout=”30” path=”/”/>
</authentication>


How to keep the session alive?



<sessionState timeout=”20” mode=”InProc” />

By default  slidingexpiration is enabled = “true” so when the momen postback occurs or user utilizing the controls, session timeout  counter is refreshed so the session remains active.