Friday, January 4, 2013
Application Pools
When you run IIS 6.0 in worker process isolation mode, you can separate different Web applications and Web sites into groups known as application pools. An application pool is a group of one or more URLs that are served by a worker process or set of worker processes. Any Web directory or virtual directory can be assigned to an application pool.
Every application within an application pool shares the same worker process. Because each worker process operates as a separate instance of the worker process executable, W3wp.exe, the worker process that services one application pool is separated from the worker process that services another. Each separate worker process provides a process boundary so that when an application is assigned to one application pool, problems in other application pools do not affect the application. This ensures that if a worker process fails, it does not affect the applications running in other application pools.
Use multiple application pools when you want to help ensure that applications and Web sites are confidential and secure. For example, an enterprise organization might place its human resources Web site and its finance Web site on the same server, but in different application pools. Likewise, an ISP that hosts Web sites and applications for competing companies might run each companys Web services on the same server, but in different application pools. Using different application pools to isolate applications helps prevent one customer from accessing, changing, or using confidential information from another customers site.
In HTTP.sys, an application pool is represented by a request queue, from which the user-mode worker processes that service an application pool collect the requests. Each pool can manage requests for one or more unique Web applications, which you assign to the application pool based on their URLs. Application pools, then, are essentially worker process configurations that service groups of namespaces.
Multiple application pools can operate at the same time. An application, as defined by its URL, can only be served by one application pool at any time. While one application pool is servicing a request, you cannot route the request to another application pool. However, you can assign applications to another application pool while the server is running.
Before Giving the Definition : you can say like this, Concept of Application pool has from IIS 6.0 .
Application pools are used to separate sets of IIS worker processes that share the same configuration and application boundaries. Application pools used to isolate our web application for better security, reliability, and availability and performance and keep running with out impacting each other . The worker process serves as the process boundary that separates each application pool so that when one worker process or application is having an issue or recycles, other applications or worker processes are not affected.
One Application Pool can have multiple worker process Also.
Main Point to Remember:
1. Isolation of Different Web Application
2. Individual worker process for different web application
3. More reliably web application
4. Better Performance
Http Handlers and Http Modules
In this blog we will see what are http handlers and modules. And in which condition which one is suitable. For that first we need to understand when user request application resource to web server, what happened? The user requests for a resource on web server. The web server examines the file name extension of the requested file, and determines which ISAPI extension should handle the request. Then the request is passed to the appropriate ISAPI extension. For example when an .aspx page is requested it is passed to ASP.Net page handler. Then Application domain is created and after that different ASP.Net objects like Httpcontext, HttpRequest, HttpResponse are created. Then instance of HttpApplication is created and also instance of any configured modules. One can register different events of HttpApplication class like BeginRequest, AuthenticateRequest, AuthorizeRequest, ProcessRequest etc.
HTTP Handler
HTTP Handler is the process which runs in response to a HTTP request. So whenever user requests a file it is processed by the handler based on the extension. So, custom http handlers are created when you need to special handling based on the file name extension.
The most common handler is an ASP.NET page handler that processes .aspx files. When users request an .aspx file, the request is processed by the page through the page handler. You can create your own HTTP handlers that render custom output to the browser.
Uses for custom HTTP handlers include the following:
RSS feeds : To create an RSS feed for a Web site, you can create a handler that emits RSS-formatted XML. You can then bind a file name extension such as .rss to the custom handler. When users send a request to your site that ends in .rss, ASP.NET calls your handler to process the request.
Image server : If you want a Web application to serve images in a variety of sizes, you can write a custom handler to resize images and then send them to the user as the handler's response.
HTTP Modules
HTTP Modules are plugged into the life cycle of a request. So when a request is processed it is passed through all the modules in the pipeline of the request. So generally http modules are used for:
Security: For authenticating a request before the request is handled.
Statistics and Logging: Since modules are called for every request they can be used for gathering statistics and for logging information.
Custom header: Since response can be modified, one can add custom header information to the response.
Serialization in .Net
Serialization is a process by which we can save the state of the object by converting the object in to stream of bytes.These bytes can then be stored in database, files, memory etc.These bytes are suitable for transmission (e.g. over the internet) or storage (e.g. on disk). What is it ? When you create an object in a .Net framework application, you don't need to think about how the data is stored in memory. Because .Net framework takes care of that for you. However, if you want to store the contents of an object to a file, send an object to another process or transmit it across the network, you do have to think about how the object is represented because you will need to convert it to a different format. This conversion is called SERIALIZATION. Uses for Serialization Serialization allows the developer to save the state of an object and recreate it as needed, providing storage of objects as well as data exchange. Through serialization, a developer can perform actions like sending the object to a remote application by means of a Web Service, passing an object from one domain to another, passing an object through a firewall as an XML string, or maintaining security or user-specific information across applications. Apply the SerializableAttribute attribute to a type to indicate that instances of this type can be serialized. Apply the SerializableAttribute attribute even if the class also implements the ISerializable interface to control the serialization process. All the public and private fields in a type that are marked by the SerializableAttribute are serialized by default, unless the type implements the ISerializable interface to override the serialization process. The default serialization process excludes fields that are marked with the NonSerializedAttribute attribute. If a field of a serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the NonSerializedAttribute attribute to that field Below is a simple code of serializing the object. MyObject objObject = new MyObject(); objObject.Value = 100; // Serialization using SoapFormatter SoapFormatter formatter = new SoapFormatter(); Stream objFileStream = new FileStream("c:\\MyFile.xml", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(objFileStream, objObject); objFileStream.Close(); Below is simple code which shows how to deserialize an object. //De-Serialization Stream objNewFileStream = new FileStream("c:\\MyFile.xml", FileMode.Open, FileAccess.Read, FileShare.Read); MyObject objObject =(MyObject)formatter.Deserialize(objNewFileStream); objNewFileStream.Close();
Thursday, January 3, 2013
Abstract Class and Interfaces
What is an Abstract Class?
An abstract class is a
special kind of class that cannot be
instantiated. So the question is why we need a class that
cannot be instantiated? An abstract class is only to be sub-classed
(inherited from). In other words, it only allows other classes to inherit from it but cannot be instantiated.
The advantage is that it enforces certain hierarchies for all the subclasses. In simple words, it is a kind of contract that
forces all the subclasses to carry on the same
hierarchies or standards.
What is an Interface?
An interface is not a class.
It is an entity that is defined by the word Interface. An interface has no implementation; it only has the
signature or in other words, just the definition of the methods without the
body. As one of the similarities to Abstract class, it is a contract that is used to define
hierarchies for all subclasses or it defines specific set
of methods and their arguments. The main difference between
them is that a class can implement more than
oneinterface but can only inherit from one abstract class. Since C#
doesn’t support multiple inheritance, interfaces are used
to implement multiple inheritance.
Both Together
When
we create an interface, we are basically
creating a set of methods without any implementation that must be overridden by
the implemented classes. The advantage is that it
provides a way for a class to be a
part of two classes: one from inheritance
hierarchy and one from the interface.
When
we create an abstract class, we are creating a base class that might have one or more completed
methods but at least one or more methods are left uncompleted and
declared abstract. If all the methods of an abstract class are uncompleted then it is same as an interface. The purpose of an abstract class is to
provide a base class definition for how a set
of derived classes will work and then allow
the programmers to fill the implementation in the derivedclasses.
There
are some similarities and differences between
an interface and an abstract class that I have arranged in a table for easier
comparison:
Feature
|
Interface
|
Abstract class
|
Multiple inheritance
|
A class may inherit severalinterfaces.
|
A class may inherit only oneabstract class.
|
Default
implementation
|
An interface cannot provide any code, just the
signature.
|
An abstract class can
provide complete, default code and/or just the details that have to be
overridden.
|
Access Modfiers
|
An interface cannot have access modifiers for the
subs, functions, properties etc everything is assumed as public
|
An abstract class can
contain access modifiers for the subs, functions, properties
|
Core VS Peripheral
|
Interfaces are used to define the peripheral abilities
of a class. In other words both Human and Vehicle can
inherit from a IMovableinterface.
|
An abstract class defines
the core identity of a classand there it
is used for objects of the same type.
|
Homogeneity
|
If various
implementations only share method signatures then it is better to use Interfaces.
|
If various
implementations are of the same kind and use common behaviour or status
then abstract class is
better to use.
|
Speed
|
Requires more time
to find the actual method in the corresponding classes.
|
Fast
|
Adding functionality
(Versioning)
|
If we add a new
method to an Interface then we have to
track down all the implementations of theinterface and
define implementation for the new method.
|
If we add a new
method to an abstract class then we have the option of providing
default implementation and therefore all the existing code might work
properly.
|
Fields and Constants
|
No fields can be
defined ininterfaces
|
An abstract class can
have fields and constrants defined
|
Design Patterns
/* Singleton Pattern */
It’s a pretty well known pattern, but I want to discuss what a
Singleton class is first. In a nutshell, a Singleton class is a class that will
only have one instance of the class. In certain cases, we want to make sure
that we cannot instantiate multiple copies of the object, so we limit it to
just one copy. Instead of having a public constructor for our class, we use a
private constructor. Then we use a public method (usually named getInstance())
to make sure there is only one copy.
Here is how it looks:
|
1
2
3
4
5
6
7
8
9
10
11
|
public class Singleton {
private static final Singleton instance;
private Singleton(){}
public static Singleton getInstance() {
if (instance == null)
instance = new Singleton();
return instance;
}
}
|
As you can see, the constructor is private, so we are unable
instantiate it in the normal fashion. What you have to do is call it like this:
|
1
|
public Singleton singleton = Singleton.getInstance();
|
When you do this, the getInstance() method then checks to see if
the parameter ‘instance’ is null. If it is, it will create a new one by calling
the private constructor. After that, it just returns it. Of course, if it is
not null, it just returns the existing instance of it. This insures that there
is only one copy of the object within your program.
Of course, this post wouldn’t have much meat to it if thats what
I left it at. So lets talk about some of the uses of a Singleton class. Also
you might at some point as ‘why not just make it static?’, which is a common
question, so I will go over that about that as well.
First, what are the uses of a Singleton?. Singleton classes are
normally used for things such as a Factory classes, Builder classes and things
like that. A few real world examples include the the SessionFactory class in
Hibernate – it’s actually a singleton. Or with log4j, when you call its logger,
it uses a singleton class to return it. If anyone has used Cairngorm within
Flex/Actionscript 3, its model locator is a Singleton.
So why do we want to use singleton’s in these instances? Lets
look at the ModelLocator example within Cairngorm. The model locator is used
within Cairngorm to keep the state of data within our Flex application. But the
reason why its kept in this one object is that it is used across multiple
components. The data in one component is usually important to another
component, so everything is managed in one central object. It’s quick to
realize why we only want one of these in our program. If not, it would be pretty
tough to maintain state if other components are affecting data providers that
others are using.
Another question that usually comes up when it comes to using a
Singleton is “Why not just use a static class?”. Static classes still have many
uses and lots of times, people get confused and will use a Singleton as much as
possible. One easy rule of thumb you can follow is if it doesn’t need to maintain state, you can use a Static class,
otherwise you should use a Singleton.
So here is a quick list of uses for static classes:
Math.pow(double a, double b);
Interger.parseInt(String s);
Interger.toString(int i);
Math.pow(double a, double b);
Interger.parseInt(String s);
Interger.toString(int i);
As you can see, the state of these methods don’t matter. You
just want to use them to perform a simple task for you. But if you coding your
application and you are using a central
object where state does matter(such as the ModelLocator example), then its best
to use a Singleton.
The next reason you may want to use a Singleton is if it is a particularly “heavy” object. If
your object is large and takes up a reasonable amount of memory, you probably
only one of those objects floating around. This is the case for things like a
if you have a factory method that is particularly robust, you want to make sure
that its not going to be instantiated multiple times. A Singleton class will
help prevent such the case ever happening.
The Singleton is a simple and powerful design pattern. Newer
programmers may not realize what potential it has and will over look it. Others
may love it so much and end of overusing it in the wrong way. Hopefully this
article was helpful for you. If so, let me know! Leave a comment or email me
at marcel@codeofdoom.com
/* Difference between Static and Singleton Class */
1.Static Class - You can not create the instance of static class.
Singleton pattern - you can create one instance of the object and reuse it.
2.Static classes- are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.
Singleton instance is created for the first time when the user requested.
3.Static Class class cannot have constructor whereas singleton class can have constructor.
4. In case of singleton class you can create the object of singleton class and pass it to
method but we can not pass the static class to method.
5.it is easy to change the logic of creating the object with some pooling mechanism but its very difficult to implement pooling mechanism with static class.
6. Singleton class does not say any restriction of Inheritence.So we should be able to do this as long as subclass is also inheritance.There's nothing fundamentally wrong with subclassing a class that is intended to be a singleton, but We can not inherit Static class to another Static class in C#.
7. After all singleton is kind of design pattern, Singletons allow you to reuse code and control object state much easier. This improves code-sharing, and can result in a far cleaner body of code. With less code, your programs will usually have fewer bugs and will be easier to maintain.
Difference between Layered and Tier Architecture
Layers refer to logical seperation of code. Logical layers help you organise your code better.
For example an application can have the following layers.
1)Presentation Layer or UI Layer
2)Business Layer or Business Logic Layer
3)Data Access Layer or Data Layer
The above three layers reside in their own projects, may be 3 projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLL's now. Depending upon how we deploy our application, we may have 1 to 3 tiers. As we now have 3 DLL's, if we deploy all the DLL's on the same machine, then we have only 1 physical tier but 3 logical layers. If we choose to deploy each DLL on a seperate machine, then we have 3 tiers and 3 layers. So, Layers are a logical separation and Tiers are a physical separation. We can also say that, tiers are the physical deployment of layers. Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model.
But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function. Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.
For example an application can have the following layers.
1)Presentation Layer or UI Layer
2)Business Layer or Business Logic Layer
3)Data Access Layer or Data Layer
The above three layers reside in their own projects, may be 3 projects or even more. When we compile the projects we get the respective layer DLL. So we have 3 DLL's now. Depending upon how we deploy our application, we may have 1 to 3 tiers. As we now have 3 DLL's, if we deploy all the DLL's on the same machine, then we have only 1 physical tier but 3 logical layers. If we choose to deploy each DLL on a seperate machine, then we have 3 tiers and 3 layers. So, Layers are a logical separation and Tiers are a physical separation. We can also say that, tiers are the physical deployment of layers. Logical layers are merely a way of organizing your code. Typical layers include Presentation, Business and Data – the same as the traditional 3-tier model.
But when we’re talking about layers, we’re only talking about logical organization of code. In no way is it implied that these layers might run on different computers or in different processes on a single computer or even in a single process on a single computer. All we are doing is discussing a way of organizing a code into a set of layers defined by specific function. Physical tiers however, are only about where the code runs. Specifically, tiers are places where layers are deployed and where layers run. In other words, tiers are the physical deployment of layers.
Friday, May 14, 2010
JAVA SCRIPT
1./* Create A Text File(If Not Exists) Through Java Script Containing WorkstationId and Telephone No on BodyOnload */
/--------- Start------------/
function fileexist()
{
var file=new ActiveXObject("Scripting.FileSystemObject");
if(file.FileExists("C:\\wstationfile.txt"))
{
var tempFile=file.OpenTextFile("C:\\wstationfile.txt",1,false,0);
var line= tempFile.ReadAll();
var newindex=line.indexOf("/");
var oldindex=0;
var str,restofstr;
restofstr=line;
while (restofstr.indexOf("/")>0)
{
str=restofstr.substring(0,newindex);
restofstr=restofstr.substring(newindex+1,restofstr.length);
newindex=restofstr.indexOf("/");
if(str.substring(0,str.indexOf("-")).toUpperCase()=="STATIONID")
{
document.getElementById("txtstation").value=str.substring(str.indexOf("-") + 1,str.length);
}
else if (str.substring(0,str.indexOf("-")).toUpperCase()=="TELEPHONENO")
{
document.getElementById("txttelephone").value=str.substring(str.indexOf("-") + 1,str.length);
}
str="";
}
document.getElementById("txttelephone").readOnly=true;
document.getElementById("txtstation").readOnly=true;
}
else
{
document.getElementById("txttelephone").readOnly=false;
document.getElementById("txtstation").readOnly=false;
}
}
function createfile()
{
var create,file;
create=new ActiveXObject("Scripting.FileSystemObject");
file=create.CreateTextFile("C:\\wstationfile.txt",true);
var str="";
str="stationid-" + document.getElementById("txtstation").value + "/";
str = str + "telephoneno-" + document.getElementById("txttelephone").value + "/";
str= str + "user-" + document.getElementById("txtusername").value + "/";
str = str + "campaing-GERECOVERY/" ;
str = str + "Lastdate-" + Date() + "/";
file.WriteLine(str);
}
/-------End--------------/
2./* Purpose:Display Month in Combo on Change of Year */
/--------- Start------------/
function ChangeMonth(j)
{
var m_names = new Array("January", "February", "March","April", "May", "June", "July", "August", "September",
"October", "November", "December");
var date=new Date();
var curr_month=date.getMonth();
var curr_year=date.getFullYear();
var curr_nextyear=curr_year + 1;;
var sel_year=document.getElementById('selYear' + j);;
var list=document.getElementById('selMonth' + j);;
var i;
if (document.getElementById('selYear' + j).value==curr_nextyear)//Purpose:If Year is Next Year,Month will start from Jan till dec
{
list=document.getElementById('selMonth' + j);
for(i = 0; i < 12; i++) { list.options[i] = new Option(m_names[i].toString(),i); } } if (document.getElementById('selYear' + j).value==curr_year)//Purpose:If Year is Current Year,Month will start from Current Month till Dec { list.options.length=0; for(i=curr_month;i < 12; i++) { list.options[i] = new Option(m_names[i].toString(),i); } if (list.options.length >0 )
{
for(var l=list.options.length-1;l>=0;l--)
{
if(list.options[l].value=="")
{
list.remove(l);
}
}
}
}
}
/--------- End------------/
3./*Purpose:To Check Java Script is Enable or Not */
function CheckJavaScript() {
if (navigator.JavaEnabled())
{
alert("The javascript is available .")
return true;
}
else
{
return false ;
}
}
4./* Purpose:Allow Only Numbers From 0 to 9 */
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
//charcode=45(-) For Negative
if (charCode > 31 && (charCode < 48 || charCode > 57) || (charCode == 45))
return false;
return true;
}
5./* Purpose:To Allow Alpha Numeric Characters */
function isAlphaNumeric(elem, helperMsg)
{
var alphaExp = /^[a-zA-Z0-9]+$/;
if (elem.value != "")
{
if(elem.value.match(alphaExp)){
return true;
}
else
{
alert(helperMsg);
elem.value="";
elem.focus();
elem.select();
return false;
}
}
}
6./* Purpose:To Allow EMail Validation */
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if (elem.value != "")
{
if(elem.value.match(emailExp)){
return true;
}
else
{
alert(helperMsg);
elem.focus();
elem.select();
return false;
}
/--------- Start------------/
function fileexist()
{
var file=new ActiveXObject("Scripting.FileSystemObject");
if(file.FileExists("C:\\wstationfile.txt"))
{
var tempFile=file.OpenTextFile("C:\\wstationfile.txt",1,false,0);
var line= tempFile.ReadAll();
var newindex=line.indexOf("/");
var oldindex=0;
var str,restofstr;
restofstr=line;
while (restofstr.indexOf("/")>0)
{
str=restofstr.substring(0,newindex);
restofstr=restofstr.substring(newindex+1,restofstr.length);
newindex=restofstr.indexOf("/");
if(str.substring(0,str.indexOf("-")).toUpperCase()=="STATIONID")
{
document.getElementById("txtstation").value=str.substring(str.indexOf("-") + 1,str.length);
}
else if (str.substring(0,str.indexOf("-")).toUpperCase()=="TELEPHONENO")
{
document.getElementById("txttelephone").value=str.substring(str.indexOf("-") + 1,str.length);
}
str="";
}
document.getElementById("txttelephone").readOnly=true;
document.getElementById("txtstation").readOnly=true;
}
else
{
document.getElementById("txttelephone").readOnly=false;
document.getElementById("txtstation").readOnly=false;
}
}
function createfile()
{
var create,file;
create=new ActiveXObject("Scripting.FileSystemObject");
file=create.CreateTextFile("C:\\wstationfile.txt",true);
var str="";
str="stationid-" + document.getElementById("txtstation").value + "/";
str = str + "telephoneno-" + document.getElementById("txttelephone").value + "/";
str= str + "user-" + document.getElementById("txtusername").value + "/";
str = str + "campaing-GERECOVERY/" ;
str = str + "Lastdate-" + Date() + "/";
file.WriteLine(str);
}
/-------End--------------/
2./* Purpose:Display Month in Combo on Change of Year */
/--------- Start------------/
function ChangeMonth(j)
{
var m_names = new Array("January", "February", "March","April", "May", "June", "July", "August", "September",
"October", "November", "December");
var date=new Date();
var curr_month=date.getMonth();
var curr_year=date.getFullYear();
var curr_nextyear=curr_year + 1;;
var sel_year=document.getElementById('selYear' + j);;
var list=document.getElementById('selMonth' + j);;
var i;
if (document.getElementById('selYear' + j).value==curr_nextyear)//Purpose:If Year is Next Year,Month will start from Jan till dec
{
list=document.getElementById('selMonth' + j);
for(i = 0; i < 12; i++) { list.options[i] = new Option(m_names[i].toString(),i); } } if (document.getElementById('selYear' + j).value==curr_year)//Purpose:If Year is Current Year,Month will start from Current Month till Dec { list.options.length=0; for(i=curr_month;i < 12; i++) { list.options[i] = new Option(m_names[i].toString(),i); } if (list.options.length >0 )
{
for(var l=list.options.length-1;l>=0;l--)
{
if(list.options[l].value=="")
{
list.remove(l);
}
}
}
}
}
/--------- End------------/
3./*Purpose:To Check Java Script is Enable or Not */
function CheckJavaScript() {
if (navigator.JavaEnabled())
{
alert("The javascript is available .")
return true;
}
else
{
return false ;
}
}
4./* Purpose:Allow Only Numbers From 0 to 9 */
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
//charcode=45(-) For Negative
if (charCode > 31 && (charCode < 48 || charCode > 57) || (charCode == 45))
return false;
return true;
}
5./* Purpose:To Allow Alpha Numeric Characters */
function isAlphaNumeric(elem, helperMsg)
{
var alphaExp = /^[a-zA-Z0-9]+$/;
if (elem.value != "")
{
if(elem.value.match(alphaExp)){
return true;
}
else
{
alert(helperMsg);
elem.value="";
elem.focus();
elem.select();
return false;
}
}
}
6./* Purpose:To Allow EMail Validation */
function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if (elem.value != "")
{
if(elem.value.match(emailExp)){
return true;
}
else
{
alert(helperMsg);
elem.focus();
elem.select();
return false;
}
Subscribe to:
Posts (Atom)
