Its April 1 st, April fools day

Last Month was a learning series of dot net framework , Next ill be publishing all the Dot Net directives each one with specific example with precise explanation. Even I am also exited about it.

Well because i am telling this on April fools day it doesn’t mean that i am making you all fool  but a kind of keep checking till than take care !!!

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

DotNet FrameWork Series Completion – Successful

Last Month we have seen most of  the basic Questions that can sometime come in our mind when we are new to Dot Net. I was also one amongst them so thought to learn and put it here so that not even me all our community can take advantage of it.

I will be more than Happy to hear any news, updates or Questions on My Framework Basic series.

you can get the complete series topic here Dotnet Framework series.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

DotNet FrameWork – Dot Net Basics Complete Series Reference – Day 0 of 30

30 March 30, 2011 DotNet FrameWork – What actually happens when you add something to an arraylistcollection – How Boxing and unboxing occures in memory – Why only boxed types can be unboxed – Day 30 of 30
29 March 29, 2011 DotNet FrameWork – What is the purpose of XML Namespaces – difference between MetaData and Manifest – What is the use of Internal keyword – Day 29 of 30
28 March 28, 2011 DotNet FrameWork – What is the difference between typeof(foo) and myFoo.GetType() – Day 28 of 30
27 March 27, 2011 DotNet FrameWork – difference between Finalize() and Dispose() – How is the using() pattern useful – What is Program Database (PDB) – Day 27 of 30
26 March 26, 2011 DotNet FrameWork – ASP.NET Web Services vs. .NET Remoting – Security – Asssembly Qualified Name – Day 26 of 30
25 March 25, 2011 DotNet FrameWork – what an Interface is and how it’s different from a Class – difference between XML Web Services using ASMX and .NET Remoting using SOAP – Serialization and Metadata – Day 25 of 30
24 March 24, 2011 DotNet FrameWork – What is PID – What is GAC – Day 24 of 30
23 March 23, 2011 DotNet FrameWork – Managed and Unmanaged Code – multicast delegates – Describe the difference between a Thread and a Process – Day 23 of 30
22 March 22, 2011 DotNet FrameWork – Resource Files – Dispose and Finallize method – encapsulation – What is inline schema, how does it work – Day 22 of 30
21 March 21, 2011 DotNet FrameWork – Check Posting of Page – system.xml Namesapce – Multiple Inheritance – Managed and Unmanaged Code – Globalization and Localization – Day 21 of 30
20 March 20, 2011 DotNet FrameWork – JIT Compilers – Tracing Methods – Debuggind Mode – Day 20 of 30
19 March 19, 2011 DotNet FrameWork – Shared Assemblies – Global Assembly – MSIL – Day 19 of 30
18 March 18, 2011 DotNet FrameWork – What is the difference between structures and enumeration, What is a namespace – Day 18 of 30
17 March 17, 2011 DotNet FrameWork – What Is Boxing And Unboxing,Value Type and Reference Type – Day 17 of 30
16 March 16, 2011 DotNet FrameWork – What is Manifest,Metadata,Delegates,Virtual Keyword,class access modifiers – Day 16 of 30
15 March 15, 2011 DotNet FrameWork – What are the types of assemblies – Day 15 of 30
14 March 14, 2011 DotNet FrameWork – What is an Assembly – Day 14 of 30
13 March 13, 2011 DotNet FrameWork – What is GUID(Globally Unique Identifier) , why we use it and where – Day 13 of 30
12 March 12, 2011 DotNet FrameWork – What are the Main Features of .NET platform – Day 12 of 30
11 March 11, 2011 DotNet FrameWork – Client device independence and basics – Day 11 of 30
10 March 10, 2011 DotNet FrameWork – What is a Formatter – Vendor Neuteality – Interoperability and Web Services – Day 10 of 30
9 March 9, 2011 DotNet FrameWork – Can Private class-level variables be inherited – Protected Internal – Can you write a class without specifying namespace – Day 9 of 30
8 March 8, 2011 DotNet FrameWork– Difference between Overriding and Overloading – Virtual Meaning – Can we Inherit Multiple Interfaces – Difference between Interface and Abstract Class – Day 8 of 30
7 March 7, 2011 DotNet FrameWork– What is DLL Hell –Deploy Assembly – Satellite Assembly – assert() – multiple Inheritance – Day 7 of 30
6 March 6, 2011 DotNet FrameWork– Dot Net Basics – Day 6 of 30
5 March 5, 2011 DotNet FrameWork– What is JIT How it works –Portable Execute – Strong Name – Global Assembly Cache – Difference B/W constants,ReadOnly and Static– Shared and Public Assembly – Types of Authentication –Difference Between Struct and Class – Day 5 of 30
4 March 4, 2011 DotNet FrameWork– difference between Finalize and Dispose (Garbage collection) – Partial Assembly References– Reflection – Basics Day 4 of 30
3 March 3, 2011 DotNet FrameWork–Managed Means–Managed Data– Reflection – Basics Day 3 of 30
2 March 2, 2011 DotNet FrameWork – Basics Day 2 of 30
1 March 1,2011 DotNet FrameWork – Basics Day 1 of 30

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

DotNet FrameWork – What is the difference between structures and enumeration, What is a namespace – Day 18 of 30

What is the difference between structures and enumeration?

Unlike classes, structs are value types and do not require heap allocation. A variable of a struct type directly contains the data of the struct, whereas a variable of a class type contains a reference to the data. They are derived from System.ValueType class.

Enum->An enum type is a distinct type that declares a set of named constants.They  are strongly typed constants. They are unique types that allow to declare symbolic names to integral values. Enums are value types, which means they contain their own value, can’t inherit or be inherited from and assignment copies the value of one enum to another.

public enum Grade

{

A,

B,

C

}

What is a namespace?

Namespace is a logical naming scheme for group related types.Some class types that logically belong together they can be put into a common namespace. They prevent namespace collisions and they provide scoping. They are imported as “using” in C# or “Imports” in Visual Basic. It seems as if these directives specify a particular assembly, but they don’t. A namespace can span multiple assemblies, and an assembly can define multiple namespaces. When the compiler needs the definition for a class type, it tracks  through each of the different imported namespaces to the type name and searches each referenced assembly until it is found.

Namespaces can be nested. This is very similar to packages in Java as far as scoping is concerned.

Please read all the post in the Dotnet Framework series.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

ASP- If a Browser Does NOT Support Cookies

If your application deals with browsers that do not support cookies, you will have to use other methods to pass information from one page to another in your application. There are two ways of doing this:

1. Add parameters to a URL

You can add parameters to a URL:

fname=John&lname=Smith”>

Go to Welcome Page</a>

And retrieve the values in the “welcome.asp” file like this:

<%

fname=Request.querystring(“fname”)

lname=Request.querystring(“lname”)

response.write(“Hello ” & fname & ” ” & lname & “!

“)

response.write(“<p>Welcome to my Web site!</p>”)

%>

2. Use a form

You can use a form. The form passes the user input to “welcome.asp” when the user clicks on the Submit button:

<form method=”post” action=”welcome.asp”>

First Name:  <input type=”text” name=”fname” value=””>

Last Name: <input type=”text” name=”lname” value=””>

<input type=”submit” value=”Submit”>

</form>

Retrieve the values in the “welcome.asp” file like this:

<%

fname=Request.form(“fname”)

lname=Request.form(“lname”)

response.write(“Hello ” & fname & ” ” & lname & “!

“)

response.write(“<p>Welcome to my Web site!</p>”)

%>

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application.

The Session Object

When you are working with an application, you open it, do some changes and then you close it. This is much like a Session. The computer knows who you are. It knows when you start the application and when you end. But on the internet there is one problem: the web server does not know who you are and what you do because the HTTP address doesn’t maintain state.

ASP solves this problem by creating a unique cookie for each user. The cookie is sent to the client and it contains information that identifies the user. This interface is called the Session object.

The Session object is used to store information about, or change settings for a user session. Variables stored in the Session object hold information about one single user, and are available to all pages in one application. Common information stored in session variables are name, id, and preferences. The server creates a new Session object for each new user, and destroys the Session object when the session expires.

When does a Session Start?

A session starts when:

  • A new user requests an ASP file, and the Global.asa file includes a Session_OnStart procedure
  • A value is stored in a Session variable
  • A user requests an ASP file, and the Global.asa file uses the <object> tag to instantiate an object with session scope

When does a Session End?

A session ends if a user has not requested or refreshed a page in the application for a specified period. By default, this is 20 minutes.

If you want to set a timeout interval that is shorter or longer than the default, you can set the Timeout property.

The example below sets a timeout interval of 5 minutes:

<%

Session.Timeout=5

%>

To end a session immediately, you may use the Abandon method:

<%

Session.Abandon

%>

Note: The main problem with sessions is WHEN they should end. We do not know if the user’s last request was the final one or not. So we do not know how long we should keep the session “alive”. Waiting too long uses up resources on the server. But if the session is deleted too fast you risk that the user is coming back and the server has deleted all the information, so the user has to start all over again. Finding the right timeout interval can be difficult.

Tip: If you are using session variables, store SMALL amounts of data in them.

Store and Retrieve Session Variables

The most important thing about the Session object is that you can store variables in it.

The example below will set the Session variable username to “Donald Duck” and the Session variable age to “50”:

<%

Session(“username”)=”Donald Duck”

Session(“age”)=50

%>

When the value is stored in a session variable it can be reached from ANY page in the ASP application:

Welcome <%Response.Write(Session(“username”))%>

The line above returns: “Welcome Donald Duck”.

You can also store user preferences in the Session object, and then access that preference to choose what page to return to the user.

The example below specifies a text-only version of the page if the user has a low screen resolution:

 

This is the text version of the page

<%Else%>

This is the multimedia version of the page

<%End If%>

Remove Session Variables

The Contents collection contains all session variables.

It is possible to remove a session variable with the Remove method.

The example below removes the session variable “sale” if the value of the session variable “age” is lower than 18:

<%

If Session.Contents(“age”)<18 then

Session.Contents.Remove(“sale”)

End If

%>

To remove all variables in a session, use the RemoveAll method:

<%

Session.Contents.RemoveAll()

%>

Loop Through the Contents Collection

The Contents collection contains all session variables. You can loop through the Contents collection, to see what’s stored in it:

<%

Session(“username”)=”Donald Duck”

Session(“age”)=50

dim i

For Each i in Session.Contents

Response.Write(i & ”
“)

Next

%>

Result:

username

age

If you do not know the number of items in the Contents collection, you can use the Count property:

<%

dim i

dim j

j=Session.Contents.Count

Response.Write(“Session variables: ” & j)

For i=1 to j

Response.Write(Session.Contents(i) & ”
“)

Next

%>

Result:

Session variables: 2

Donald Duck

50

Loop Through the StaticObjects Collection

You can loop through the StaticObjects collection, to see the values of all objects stored in the Session object:

<%

dim i

For Each i in Session.StaticObjects

Response.Write(i & “<br />”)

Next

%>

A group of ASP files that work together to perform some purpose is called an application. The Application object in ASP is used to tie these files together.

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

ASP – 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 for a page with a browser, it will send the cookie too. With ASP, you can both create and retrieve cookie values.

How to Create a Cookie

The “Response.Cookies” command is used to create cookies.

Note: The Response.Cookies command must appear BEFORE the <html> tag.

In the example below, we will create a cookie named “firstname” and assign the value “Alex” to it:

<%

Response.Cookies(“firstname”)=”Alex”

%>

It is also possible to assign properties to a cookie, like setting a date when the cookie should expire:

<%

Response.Cookies(“firstname”)=”Alex”

Response.Cookies(“firstname”).Expires=#May 10,2002#

%>

How to Retrieve a Cookie Value

The “Request.Cookies” command is used to retrieve a cookie value.

In the example below, we retrieve the value of the cookie named “firstname” and display it on a page:

<%

fname=Request.Cookies(“firstname”)

response.write(“Firstname=” & fname)

%>

Output:

Firstname=Alex

A Cookie with Keys

If a cookie contains a collection of multiple values, we say that the cookie has Keys.

In the example below, we will create a cookie collection named “user”. The “user” cookie has Keys that contains information about a user:

<%

Response.Cookies(“user”)(“firstname”)=”John”

Response.Cookies(“user”)(“lastname”)=”Smith”

Response.Cookies(“user”)(“country”)=”Norway”

Response.Cookies(“user”)(“age”)=”25″

%>

Read all Cookies

Look at the following code:

<%

Response.Cookies(“firstname”)=”Alex”

Response.Cookies(“user”)(“firstname”)=”John”

Response.Cookies(“user”)(“lastname”)=”Smith”

Response.Cookies(“user”)(“country”)=”Norway”

Response.Cookies(“user”)(“age”)=”25″

%>

Assume that your server has sent all the cookies above to a user.

Now we want to read all the cookies sent to a user. The example below shows how to do it (note that the code below checks if a cookie has Keys with the HasKeys property):

<html>

<body>

<%

dim x,y

for each x in Request.Cookies

response.write(“<p>”)

if Request.Cookies(x).HasKeys then

for each y in Request.Cookies(x)

response.write(x & “:” & y & “=” & Request.Cookies(x)(y))

response.write(“<br />”)

next

else

Response.Write(x & “=” & Request.Cookies(x) & “<br />”)

end if

response.write “</p>”

next

%>

</body>

</html>

Output:

firstname=Alex

user:firstname=John
user:lastname=Smith
user: country=Norway
user: age=25

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

ASP – Lifetime of Variables

A variable declared inside a procedure is created and destroyed every time the procedure is executed. No scripts outside the procedure can access or change the variable.

To declare variables accessible to more than one ASP file, declare them as session variables or application variables.

Session Variables

Session variables are used to store information about ONE single user, and are available to all pages in one application. Typically information stored in session variables are name, id, and preferences.

Application Variables

Application variables are also available to all pages in one application. Application variables are used to store information about ALL users in a specific application.

Procedures

The ASP source code can contain procedures and functions:

<html>

<head>

<%

sub vbproc(num1,num2)

response.write(num1*num2)

end sub

%>

</head>

<body>

Result:

</body>

</html>

Insert the <%@ language=”language” %> line above the tag to write procedures or functions in another scripting language than default:

<%@ language=”javascript” %>

<html>

<head>

<%

function jsproc(num1,num2)

{

Response.Write(num1*num2)

}

%>

</head>

<body>

Result:

</body>

</html>

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )