Tuesday, March 11, 2014

How do you validate email

protected void btnValidate_Click(object sender, EventArgs e)
{
bool isEmail = Regex.IsMatch(txtEmail.Text.Trim(), @"\A(?:[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)\Z");
if (!isEmail)
{
   lblerrormsg.Text = "Enter Valid Email ID..";
   lblerrormsg.ForeColor = System.Drawing.Color.Red;
   return;
}
else
{
   lblerrormsg.Text = "Valid Email";
   lblerrormsg.ForeColor = System.Drawing.Color.Green;
}
}

Wednesday, January 22, 2014

What is master page?

Master Page is used in web application
We can say master page as a template for the other pages in our project.
For creating a constant look and feel for all our pages in web application.
It acts as a placeholder for the other pages or content.
If a user makes a request to a webpage it merges with masterpage and will provide the output .

What is publisher subscriber model? Any design pattern can be implemented for it?

It is also called as Observer design pattern.
Windows Communication Foundation (WCF) is the best exampled for this model.
The user can publish a Service and it can be consumed by many clients at the end point.
The Publisher gives the data to the clients who have subscribed to their methods.

What is Nuget?

It is Visual Studio extension and a open source project
By using Nuget we can easily add,update and remove libraries in Visual Studio Projects.
When you add or remove a library it copies/removes necessary files to your application.
It is a quick way to add reference to our application.

What is difference between a.equals(b) and a==b?

“==” --> It compares reference
"Equals" --> It compares object by VALUE.

Monday, January 28, 2013

What is the difference between the Page_Init and Page_Load events?

Page_Init

The Page_Init event is the first to occur when an ASP.NET page is executed.This is where you perform any initialization steps that you need to set up or create instances of server controls.You can't access controls in this event because there is no guarantee that they have been created yet.
The Page_Init event fires only the first time the page is loaded.
When you postback to any page, the Page_Init event doesn't fire.

Page_Load
The Page_Load event fires each time the page loads, postback or not.

This event occurs only when all the objects on the page have been created and are available for use.



Thursday, November 1, 2012

what is Marshaling?

Marshaling is a process of making an object in one process (the server) available to another process (the client). There are two ways to achieve the marshalling.

Marshal by value: The server creates a copy of the object passes the copy to the client. When a client makes a call to an object marshaled by value (MBV), the server creates an exact copy and sends that copy to the client. The client can then use the object's data and executable functionality directly within its own process or application domain without making additional calls to the server. Objects that the application accesses frequently are best remoted using MBV.

Marshal by reference: The client creates a proxy for the object and then uses the proxy to access the object. When a client makes a call to an object marshaled by reference (MBR), the .NET framework creates a proxy in the client's application domain and the client uses that proxy to access the original object on the server. Large objects that the application accesses relatively infrequently are good candidates for MBR.

What are remotable objects in .NET Remoting?

Remotable objects are the objects that can be marshaled across the application domains.
You can marshal by value, where a deep copy of the object is created and then passed to the receiver.
You can also marshal by reference, where just a reference to an existing object is passed.

When would you use .NET Remoting and when Web services?

.Net Remoting
Used for more efficient exchange of information when you control both ends of the application.

Web Services
Used for open-protocol-based information exchange when you are just a client or a server with the other end belonging to someone else.

If I’m developing an application that must accommodate multiple security levels though secure login and my ASP.NET web application is spanned across three web-servers (using round-robin load balancing) what would be the best approach to maintain login-in state for the users?

use the security state maintained using a database. (Use Authentication mode as database


Which are the namespaces that are imported automatically by Visual Studio in ASP.Net?

There are 7 namespaces which are imported automatically.

 
System

System.Collections

System.IO

System.web

System.web.UI

System.web.UI.HTMLControls

System.web.UI.WebControls

What are the types of Authentication? Describe

There are 3 types of Authentication.
(a)Windows Authentication
(b) Forms Authentication
(c) Passport Authentication.


Windows authentication uses the security features integrated into the Windows NT and Windows XP operating systems to authenticate and authorize Web application users.

Forms authentication allows you to create your own list/database of users and validate the identity of those users when they visit your Web site.

Passport authentication uses the Microsoft centralized authentication provider to identify users. Passport provides a way to for users to use a single identity across multiple Web applications. To use Passport authentication in your Web application, you must install the Passport SDK.

Thursday, October 25, 2012

Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming

Aspect-Oriented

Aspect-oriented programming looks at how many components or pieces of a system might need to interact. The intersections of these pieces are what are important in AOP. "Crosscutting" is a slice across several units, all of which interact during some operation.
Interface-Oriented
Interface-oriented programming is a contract-based approach. Nether side of the interface cares how the other does its work, only that the two sides can communicate via an agreed-upon contract. WSDL-based web services are the prime example of this.

Object-Oriented
Object-Oriented programming is based on abstraction, encapsulation (data hiding), polymorphism and inheritance. Classes implement these concepts to build objects controlling or implementing a system.

Abstraction allows loose coupling between components by providing a layer between objects so that one object isn't concerned with how the other implements its business rules. (Interfaces, layers) Great stuff when you want to isolate parts of the system so they can be swapped out without killing the rest of the sytsem.

Encapsulation allows abstraction to work by hiding details of a class's implementation from calling classes. (Public vs. private fields)

Inheritance enables base (parent) classes to have common functionality defined in it and passed down to child classes. A Shape class might have a field for color which is inherited by child classes of Square or Circle type.

Polymorphism enables implementation of same-named public fields, allowing different classes to perform different actions on the same call - rendering a Square or Circle object differently in a graphic program, even though they might both be subclassed from a base Shape class. (Overriding)

What are trace switches?

Trace switches helps us to control and govern the tracing behavior of a project. There are two types of trace switches ‘BooleanSwitch’ and ‘TraceSwitch’. BooleanSwitch, as the name says, is a kind of on/off switch which can be either enabled (true) or disabled (false).

‘TraceSwitch’ on the other hand offers more options rather than simple true/false like ‘BooleanSwitch’. Tracing is enabled for a TraceSwitch object using the Level property. When we set the Level property of a switch to a particular level, it includes all levels from the indicated level down. For example, if you set a TraceSwitch’s Level property to TraceLevel.Info, then all the lower levels, from TraceLevel.Error to TraceLevel.Warning, will be taken in to account.

Below are the various levels in ‘TraceSwitch’ object.
 
Off a Outputs no messages to Trace Listeners

Error a Outputs only error messages to Trace Listeners

Warning a Outputs error and warning messages to Trace Listeners

Info a Outputs informational, warning and error messages to Trace Listeners

Verbose a Outputs all messages to Trace Listeners

 
 
 
 
 
 
 
 

What is the main difference between Gridlayout and FlowLayout ?

GridLayout provides absolute positioning for controls placed on the page. Developers that have their roots in rich-client development environments like Visual Basic will find it easier to develop their pages using absolute positioning, because they can place items exactly where they want them. On the other hand, FlowLayout positions items down the page like traditional HTML. Experienced Web developers favor this approach because it results in pages that are compatible with a wider range of browsers.

If you look in to the HTML code created by absolute positioning you can notice lot of DIV tags. While in Flow layout you can see more of using HTML table to position elements which is compatible with wide range of browsers.



What is the difference between “Web farms” and “Web garden”?

Web farm
Used to have some redundancy to minimize failures. It consists of two or more web server of the same configuration and they stream the same kind of contents. When any request comes there is switching / routing logic which decides which web server from the farm handles the request. For instance we have two servers “Server1″ and “Server2″ which have the same configuration and content. So there is a special switch which stands in between these two servers and the users and routes the request accordingly.

A router in between which takes a request and sees which one of the server is least loaded and forwards the request to that server. So for request1 it route’s server1, for request2 it routes server2, for request3 it routes to server3 and final request4 is routed to server4. So you can see because we have web farm at place server1 and server2 are loaded with two request each rather than one server loading to full. One more advantage of using this kind of architecture is if one of the servers goes down we can still run with the other server thus having 24×7 uptime.

The routing logic can be a number of different options:

Round-robin: Each node gets a request sent to it “in turn”. So, server1 gets a request, then server2 again, then server1, then server2 again.

Least Active Whichever node show to have the lowest number of current connects gets new connects sent to it. This is good to help keep the load balanced between the server nodes

Fastest Reply Whichever node replies faster is the one that gets new requests. This is also a good option – especially if there are nodes that might not be “equal” in performance. If one performs better than the other, then send more requests there rather than which is moving slowly?

Web Garden

All requests to IIS are routed to “aspnet_wp.exe” for IIS 5.0 and “w3wp.exe” for IIS 6.0. In normal case i.e. without web garden we have one worker process instance (“aspnet_wp.exe” / “w3wp.exe”) across all requests. This one instance of worker process uses the CPU processor as directed by the operating system.

But when we enable web garden for a web server it creates different instances of the worker process and each of these worker process runs on different CPU.
In short we can define a model in which multiple processes run on multiple CPUs in a single server machine are known as a Web garden.



If cookies are not enabled at browser end does form Authentication work?

No,it does not work

ASP used STA threading model, what is the threading model used for ASP.NET ?

ASP.NET uses MTA threading model

Tuesday, October 23, 2012

What are the benefits of service orientation?

[1] Isolation : Changing the internals of one service does not force changes, rebuilding or restarting of other services.

[2] Behavior is separated from constraints : Relocating, outsourcing or restricting a service requires changes only in the policy but not to the service itself.

[3] Location independent : Whether a service is on the same machine or different, it can be accessed in the similar manner.

[4] Scale invariant : Services scale in all the directions. Let's take an example a service can be scaled out by fronting it with a router service that distributes traffic among a farm of services.

[5] Transport/protocol/format neutral : The communication details between parties are flexible but not fixed.

[6] Time independent : Services can make use of queue-based communication, when they do not have to be online at the same time to interact.

[7] Platform and implementation independent : A service need not know anything about another service's execution environment to interact with it.

[8] Address agnostic : Services can employ a discovery mechanism to locate each other without any prior notion about where they reside.

Set Operators in Linq

There are mainly five types of Set Operators in Linq.


1. Distinct

2. Concat

3. Union

4. Intersect

5. Except

1.Distinct
public void DistinctFunction()
{
int[] seq1 = { 1, 2, 3, 3, 4, 2, 5, 4, 5, 2, 1 };
var distinctValues = seq1.Distinct();
Console.WriteLine("Distinct Values in the array : ");
foreach (var n in distinctValues)
{
Console.WriteLine(n);
}
}
OutputDistinct Values in the array :
1
2
3
4
5



2.Concat
public void ConcatFunction()
{
int[] seq1 = { 1, 2, 3 }, seq2 = { 3, 4, 5 };
var concatValues = seq1.Concat(seq2);
Console.WriteLine("Concatenation of two array : ");
foreach (var n in concatValues)
{
Console.WriteLine(n); }
 }
OutputConcatenation of two array :
1
2
3
3
4
5

3.Union

public void UnionFunction()
{
    int[] seq1 = { 1, 2, 3 }, seq2 = { 3, 4, 5 };
 
    var unionValues = seq1.Union(seq2);
 
    Console.WriteLine("Union of two array : ");
    foreach (var n in unionValues)
    {
        Console.WriteLine(n);
    }
}

Output

Union of two array :
1
2
3
4
5


4.Intersect
public void IntersectFunction() {    int[] seq1 = { 1, 2, 3 }, seq2 = { 3, 4, 5 };    var unionValues = seq1.Intersect(seq2);    Console.WriteLine("Intersection of two array : ");    f oreach (var n in unionValues)    {      Console.WriteLine(n);    } } OutputIntersection of two array :  3   5.Except public void ExceptFunction() {  int[] seq1 = { 1, 2, 3 }, seq2 = { 3, 4, 5 };  var unionValues = seq1.Except(seq2); Console.WriteLine("Applying Except Function on two arrays : "); foreach (var n in unionValues) {  Console.WriteLine(n);  } } OutputApplying Except Function on two arrays :  1  2