Most Viewed

Most Viewed

Saturday 11 August 2012

C#4.0 Dynamic Vs Var keyword


C#4.0 Dynamic Vs Var keyword


In C # 4.0, There is a new keyword called dynamic, We can use ia as any datatype like float,int,string, double etc.

Actually we can implement the samething using Var keyword also, But there is a different behavior.

If you want to declare a variable of type with the var keyword, var implicitly static, I'll explain its meaning.

When we declare a string of some data (initialization that is) must be of type String and then the compiler  will use reflection to get all info about the type at the compile time.
See the example given Below:


Now Here we declared a string 

 Var someStr = "Example Some String ";
Response.Write(SomeStr.Length);
Var Keyword Implementation
 Similarly if we use dynamic keyword, It behaves like a Object
Dynamic Keyword Implementation













 We can access methods,properties,operators using Dynamic Keyword

According to the MSDN blog “Variables declared with var are implicitly but statically typed. Variables declared with dynamic are dynamically typed. This capability was added to the CLR in order to support dynamiclanguages like Ruby and Python.”







Read more ...

Generate Random password using C#.Net

 Generating Random password in C#.Net

I create a lot of code to C # with a random password to see. NET. But I feel the following code is very simple to create. Maybe I'm wrong, but I have my solution to this problem.



If you want a better way go through the given below code:

static string CreateRandPass(int numberOfChar)
{
           if (
numberOfChar <= 0 || numberOfChar > 32)
           {
               throw new ArgumentException(“A password of only length 1 to 32 can be generated.”);
           }
           string guidWithoutDashes = Guid.NewGuid().ToString(“n”);
           //Console.WriteLine(“Guid without  :- ” + guidWithoutDashes);
           var chars1 = new char[numberOfChar
];
           var random = new Random();
           for (int i = 0; i < chars.Length; i++)
           {
               chars[i] = guidWithoutDashes[random.Next(guidWithoutDashes.Length)];
           }
           //Console.WriteLine(“Random password is:- ” + new string(chars));
           return new string(chars);
}


xcgvdfgfg
Read more ...

Thursday 2 August 2012

OutProcess Sessions



Enhancement of session state in ASP.NET
1.           ASP.NET supports out process session, this is also called as process independent sessions.
2.           ASP.NET supports cookie less session.


 

When the session are maintained within the process of application domain, then it will not provide reliability because session will be destroyed when application domain is destroyed. The application domain will be recycled in the following cases.
a.            When you make changes to web.config, application domain will be recreated with new settings.
b.           When the web server is restarted the application domain will be recreated.

When the session are maintained outside the application domain process (i.e. ASP.NET worker Process)
This out process session provides more reliability and a solution for web forming.
The external process for maintaining sessions can be state server or SQL server.
This is a service of the Operating system that will be installed with .net framework. This comes as a file ASPNET_State.Exe. This will maintain session data in the form of inmemory storage.



Read more ...

State Management in ASP.Net



State Management

The connection between the client and the server will be closed once the response is returned to the client.
This is called as stateless nature of the web.
When the web server maintains the information about the client, then it is called as state management concept.
1.                       Submission of data using post method.
2.                       Cookies
3.                       Session memory
4.                       Application memory
5.                       Cache data (new in asp.net)

Submission of data

Http context is the memory area in which the instances of the classes will be executed. By getting the reference to this memory area. We can access the handler class instance.

Cookie

Cookie can be defined as small amount of memory used by the web server within client machine.
Basically cookies are used to maintain personal information of the client
The cookies can be classified in two types.
1.                       Inmemory cookie
2.                       Persistent cookie

When the cookie is stored within the process memory of the browser then it is called as Inmemory cookie.
Inmemory cookie is a temporary cookie because when the browser will be closed the data will be lost.
When the browser is storing cookie on to the hard disk memory, then it is called as persistent cookie.
It is provided with particular lifetime.

Creating a cookie:
Dim obj as new httpCookie (“name”, value)
Obj.expires=#mm/dd/yyyy/hh:mm:ss#(requires incase of Persistent cookie)
Response.appendcookie (obj)àthis will write cookie information to the client machine

Reading the cookie:
Dim obj as httpcookie
Obj=request. Cookies (“name”)àit returns an object of httpcookie class, if the obj is nothing then cookie is not available.

Each request from the client will carry all the cookies information to web server.

The cookies will be stored into the hard disk memory of the client machine, with respect to network login folder.
(C:\document and settings\administrator (login folder)\cookies\administrator@localhost.txt)

The cookie information is maintained in the client machine, so it is called as client side state management.
It does not provide any security because it is available in the client machine. So the client can modify the value of the cookie as well as delete the text file.
A cookie can represent maximum of 4KB data.
A website can be used with maximum of 20 cookies because a browser can accommodate only 20 cookies towards single website.
A browser can accommodate maximum of 400 cookies with respect to different websites.

Session Memory
When the first request from the client goes to the web server, the web server will create a unique memory to the client on the server machine.
This session memory provides server side state management.
A cookie can represent only ordinary text, where as a session can represent ordinary text, arrays, objects etc.
The session will be maintained on the web server with the time out of 20 minutes (by default), but this can be changed as per the requirements.
Using session object we can access the session memory.
Session properties are,
1. Session id
2. Time out (To close session implicitly)
Session methods are,
1. Add (varname, value)
2. Remove (varname)
3. Abandon (to close session explicitly)

When it comes to ASP 3.0, session variable can’t be removed, i.e. erased until session is closed. When it comes to ASP.NET, session variable can be removed by using remove method.

Session Tracking
It is a concept of identifying the session by the web server belonging to a particular user.
When user sends the 2nd request to the server, the session ID will be carried with the request, so the server can trap the session memory assigned for the particular user.
The session id will be 120-bit number. (i.e. 15 bytes) in the hexadecimal format.

Application memory
When the first client’s first request comes to the web server towards a particular application, then web server will allocate memory for the application. This memory is called as application memory.
This memory will be common to all the users.
The application memory does not have timeout, this will be maintained till the web server is active. (i.e. executing)
E.g. At the time of chatting we require a common field i.e. application memory not the session memory.

By using application object, we can access the application memory from the web page.
Like session, application objects are having some methods.
1. Add (var, value)
2. Remove (var)
3. Lock ()
4. Unlock ()

Each client request to the web server will start a new thread, when one thread is processing the data in the application memory before the processing is finished, if the time slice is completed the processor will go to next client request, if this thread is processing data in the application memory, then the result will not be proper. To avoid this it is advisable to allow only one thread at a time to work with application memory. This can be achieved through lock () and Unlock () methods.
This process is called as synchronization of threads.

SESSION EVENTS AND APPLICATION EVENTS
1. Session OnStart ()
2. Session OnEnd ()

When a session memory is created OnStart () event will be executed.
Before releasing the session memory OnEnd () event will be executed.

Application Events are,
1. Application OnStart ()
2. Application OnEnd ()
3. Application BeginRequest ()
4. Application EndRequest ()
   (Newly provided in ASP.NET)

When a request comes for a particular web page then begin request will be executed, then the particular requested page will be processed and then the end request will be executed.

GLOBAL.ASAX

Session and application events have to be placed within a special file called as global.asax.
a. Global.asax file has to be stored within the root directory of the application.
b.                       An application can have only one Global.asax file.


When the first client’s first request comes to the asp.net runtime, i.e. web server towards a particular application, then it will create application memory and an instance of global class within global.asax file. This instance will be maintained through out the application for making calls to the session events and application events.






Read more ...

Sunday 22 July 2012

Authentication & Authorization in ASP.Net

Authentication & Authorization in ASP.Net


This is a new security concept provided with asp.net.When client request comes to the web server, then web server will attach one user account for the anonymous user, based on which resources will be accessible. This is called as impersonation.
By default IUSR_MACHINENAME is the account attached to the anonymous user.
When you want to implement current security for the web application, then we require authentication and authorization.

Authentication, is nothing but the process of getting identity or credential of the user (means username and password)
Authorization is the process of giving access or denying access to a particular resource based on identity of the user.



Asp.net supports three types of authentication.
1.                       Windows based authentication
2.                       Form based authentication
3.                       Passport based authentication

Windows based authentication
This can be used only to the private website related to the organization i.e. intranet implementation.
This will perform authentication based on windows operating system.
(That is network label login or role)

Form based authentication
This will perform authentication based on users information maintained within database server. This is required for the commercial websites.
When client provides proper authentication information, asp.net runtime will respond with redirecting to requested page along with writing a cookie to the client machine.
This cookie will contain security token, so that subsequent request will be processed without authentication.

Redirectfromloginpage () will provide the user with the requested web page, based on the second parameter, cookie will be created with security token in the form of Inmemory cookie or persistent cookie. If it is Inmemory cookie the authentication is not required only for one browser window. If it is persistent cookie all the browser window from the system does not require authentication. The name of the cookie by default is aspxauth.
Providing name attribute within forms tag the cookie name can be changed.
The lifetime with the cookies by default is 30 minutes.

Passport authentication
When you want to perform common authentication for collection of website, then we require passport authentication. In this client will be authenticated only once and access is given to different websites. This is called as single sign on service 
The main disadvantage is that, the company’s client details will be mainted by Microsoft database.

Read more ...

Saturday 21 July 2012

Caching in ASP.Net



   Caching in ASP.Net

When you store most frequently used data on to the temporary storage and providing to different clients request, then it is called as caching.
The main advantage of caching is to improve the performance of the web server by reducing the processing time.
When you are expecting more no. of requests to a web page within a particular time interval, also the web page is having database interaction and the data within the database is not changing frequently then apply the caching.

ASP 3.0 supports, entire page caching only at client side.
ASP.Net supports 3 types of caching,
a. Output Caching (Entire page Caching) 
b. Fragment Caching (Portion of web Page as Caching)
c. Data Caching (memory Variable Caching)

Output caching is also termed as entire page caching.
When you want to maintain multiple buffers content towards a single web page then we require varybyparam option.
To achieve this output caching go to html view,
<%@ outputcache duration=”seconds” varybyparam=”none”%>

User defined control.
Web user control will provide reusability of graphical interfaces and coding.
It will compile dynamically along with web page.
The extension of the file is .ascx
This is local to the application, so it will not appear in the toolbox.
Caching can be applied to web user control.
When you want to make use of web user control within a web page then .ascx file has to be registered with the web page.
i.e. under html view,
<%@ Register TagPrefix="uc1" TagName="WebUserControl1" Src="WebUserControl1.ascx"%>

      A web user control is similar to webform but can’t be called independently.
It has to be contained by web form.

When you apply caching on a portion of web page then it is called as fragment caching. This can be achieved under web user control.

Data caching
When you apply caching on the memory variables, then it is called as data caching. This can be classified into three types.
1.           Ordinary caching
2.           File based dependency data caching
3.           Time based dependency data caching

In asp.net the alternative for application memory is provided with data caching.
This will overcome all the drawbacks of application memory variable like,
1. Data caching is a thread safe as compared to application memory.
So the lock method will be applied implicitly to the variable, which is used for modification.
Application. Lock ()
Application. Unlock ()
(Not required in case of caching)

2. Data caching supports expiry policy for the data, which is not supported by application memory variable.

System.web.caching (namespace)
                                   
Cache class
CacheDependency Class

Ordinary data caching
Cache. Insert (“A”, 100)
Or
Cache (“A”) = 100
File based dependency data caching
When you want to provide expiry policy of data, based on time stamp of the file, then it is called as file based dependency data caching.


Time based dependency data caching
When you want to provide expiry policy of data, based on time, then it is called as time based dependency data caching.
Time can be based on two types.
1.           Absolute time will be considered from storage time.
2.           Sliding time will be considered from the last access.

When it comes to data caching, the content will be erased, when application demands for the memory.


Read more ...

Tuesday 17 July 2012

ASP.Net Page Execution


ASP.Net Page Execution


·     Asp.net webpage is a class inherited from page class….
·     It will be compiled into dll file.
·     An object of -----.aspx class will be created, this will produce output to client browser.
·     The object will be destroying after providing output to client browser. The dll file will be maintained by server.
·     When the subsequent client request comes to webpage the object will be created from the dll and output will be provided to client.

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

 

 ·     Asp.net worker process can be called as asp.net runtime. This will maintain http app factory and page handler factory. http app factory will contain app names running under worker process. Page handler factory will contain compiled webpage names. The requested app will be verified with http app factory. If it is not available it will create a block of memory and files related to app will be loaded into memory. This memory is called app domain.
·     The requested webpage will be verified with page handler factory. If it is not available the request will be given to http pipeline.
·     http pipeline is a collection of .net framework classes which will produce dll file for the webpage.
·     The request will be forwarded to http runtime this will encapsulate .net runtime (clr) it will create an object of webpage class and makes a call to process request method.
Read more ...

Sunday 15 July 2012

.Net Fundamentals & Architecture

                                      .NET fundamentals



.NET is a platform to create distributed applications

The Core Purpose of .NET is to connect different devices,systems,information and people.


.Net takes the best of XML to leverage the speed of Internet applications
.NET creates XML web services through which we can expose the needy methods to the users thru internet.
The clients on the other end can consume the web services.

This is one of the powerful features of .NET that makes reusability very easy.

The Advantages of .NET platform:

1.Side-by-side execution:

  .NET allows two different versions of the same component to be installed on the same system.
  i.e. we can run .NET framework 1.1 and 2.0 on the same PC

2.Ease of Deployment:
    .NET  allows different scenarious  for the deploying of the application  ex. XCopy deployment,windows installer,clickOnce etc
   these make the developers job much  more easier without any fuss of registering and coding.

3.Language independent:
  .NET is totally language independent as it supports huge number of languages alomost   40+
ex. c#,vb.net,j# cobol.net,php.net,fortran.net etc

4.partially platform independent :

 The .NET framework works on Windows and a project called 'mono-project' is being conducted to make it available for unix and linux as well
     

4.Highly Scalable:
.NET apps are highly scalable and can accomodate wide number of users.
 for example we can increase the performance of our website depending on the number of visitors.
Many of the performance tuning techniques of .NET help us to achieve this scalability

5.Secure

.NET provides high level of security to the applications by sophisticated and standard security mechanisms

6.Ease of development:

.NET increases the developer productivity as it allows the programmer to focus on the business logic alone.
all the mundane tasks of development were handled by .NET itself


    The Architecture of .NET


The languages supported by .net are called as .NET aware languages.

CLS: common language specification

 we can use a VB.NET class in a C# class.any of the .net aware languages  can utilize the other .net aware languages classes. This mechanism is called inter-operability
      this interoperability is achieved thru the CLS
     CLS contains a set of rules to be followed by all the .net aware languages

CTS:common type system

   CTS is the subset of CLS.
CTS promotes interoperability between the datatypes.

ex. vb.NET represents integer datatype with keyword 'Integer'
The C# with 'int'
if i need to use a c# class with vb.net the CTS type known as 'Int32' acts a representation of integer.
thus interoperability between datatypes is achieved thru CTS types.    

ASP.NET: ActiveServerPages.NET

  This is a technology to create Internet applications and mobile web Apps.
  It is mostly used to create websites
 we can use vb.net ,c# or j# to develop these sites.


WindowsForms: These are classic vb apps which represent desktop applications.
Mostly used for Gaming and graphical desinging.

ADO.NET: ActiveX Data Objects.NET

Any app deals with data. Inorder to retrieve data or dislay data or manipulate the information we can take the help of ADO.NET objects
ADO.NET is a collection of objects which enhance the power of dealing with the data
ADO.NET works in conjuction with XML to achieve data exchange

BCL: Base Class Library

this is the repository of huge number of classes all prepackaged to ease the development of .NET application
BCL contains 13000 classes which are organized as namespaces.
A namespace is a category which represent a certain classes belonging to specific functionality.

CLR:Common language runtime or runtime
   This is the foundation on which the total .net architecture lies upon  It performs all the major tasks of the framework

CLR functionalities:-

1. Compilation and CodeExecution
2. Automatic Memory Management
3. Exception Handling
4. Threading
5. Security
6. Type Safety


1.Compilation and Execution
Any .NET code is first compiled into MSIL -microsoftintermediate language. later this IL code is converted to native code by JIT(just-in-time)Compiler or jitter


Visualstudio.net: this is IDE -integrated development environment to create .NET apps.
 This is a design tool integrated with all .nET technologies to create .NEt software
the latest version is visualstudio2005








 
  
Read more ...