.NET interview questions,c# interview questions ,
C# and ASP.NET MVC interview question: - What are “ActionFilters”in MVC?

“ActionFilters” helps you to perform logic before a MVC action happens or after a MVC action is completed. Action filters are useful in the following scenarios:-

1. Implement pre-processing / post processing logic before or after the action happens.

2. Cancel a current execution.

3. Inspect the returned value.

4. Provide extra data to the action.
 

Also read ASP.NET interview question :- What is difference between “Server.Transfer” and “Response.Redirect”?
 

Do visit for more c# and MVC interview questions and answer at  www.questpond.com
 

The above question is taken from the book published by Bpb publication .NET interview question by Shivprasad koirala.

ASP.NET and MVC Interview questions: - How can you do authentication and authorization in MVC?

Start learning MVC step by step from here Learn MVC step by step

You can use windows or forms authentication for MVC.

For windows authentication you need to go and modify the “web.config” file and set authentication mode to windows.

 

Then in the controller or on the action you can use the “Authorize” attribute which specifies which users have access to these controllers and actions. Below is the code snippet for the same. Now only  the users specified in the controller and action can access the same.

Forms authentication is implemented the same way as we do in ASP.NET. So the first step is to set authentication mode equal to forms. The “loginUrl” points to a controller here rather than page

We also need to create a controller where we will check the user is proper or not. If the user is proper we will set the cookie value 

All the other actions need to be attributed with “Authorize” attribute so that any unauthorized user if he makes a call to these controllers it will redirect to the controller ( in this case the controller is “Login”) which will do authentication.

 

Below is an important c# interview question and answers video:- Can you explain extension methods? 

See more stuffs on c#  and ASP.NET MVC interview question and answers

Regards,

Click here to view more c#/ASP.NET MVC interview question and answers

ASP.NET MVC (Model view controller) interview questions: - Is MVC different from a 3 layered architecture?

In case you are new to MVC start learning by click on this video learn MVC step by step.

MVC is an evolution of a 3 layered traditional architecture. Many components of 3 layered architecture are part of MVC.  So below is how the mapping goes.

 

Below is an important c# interview question video


See more stuffs on  ASP.NET interview questions

Regards,

Click here to view more C#/ASP.NET interview questions and answers


UML Training: - How many types of diagrams in UML(Unified Modeling Language)?

There are nine types of diagrams in UML:-

Use case diagram:

They describe “WHAT” of a system rather than “HOW” the system does it. They are used to identify the primary elements and processes that form the system. The primary elements are termed as “actors” and the processes are called “use cases”. Use Case diagrams shows “actors” and there “roles”.

Class diagram:

From the use case diagram, we can now go to detail design of system, for which the primary step is class diagram. The best way to identify classes is to consider all “NOUNS” in use cases as classes, “VERBS” as methods of classes, relation between actors can then be used to define relation between classes. The relationship or association between the classes can be either an “is-a” or “has-a” relationship which can easily be identified from use cases.

Object diagram:

An object is an instance of a class. Object diagram captures the state of classes in the system and their relationships or associations at a specific point of time.

State diagram:

A state diagram, as the name suggests, represents the different states that objects in the system undergo during their life cycle. Object change in response to certain simulation so this simulation effect is captured in state diagram. Therefore, it has a initial state and final state and events that happen in between them. Whenever you think that some simulations are complicated, you can go for this diagram.

Sequence diagram:

Sequence diagrams can be used to explore the logic of a complex operation, function, or procedure. They are called sequence diagrams because sequential nature is shown via ordering of messages. First message starts at the top and the last message ends at bottom. The important aspect of a sequence diagram is that it is time-ordered. This means that the exact sequence of the interactions between the objects is represented step by step. Different objects in the sequence diagram interact with each other by passing “messages”.

Collaboration diagram:

A collaboration diagram groups together the interactions between different objects to fulfill a common purpose.

Activity diagram:

Activity diagram is typically used for business process modeling, for modeling the logic captured by a single use case, or for visualizing the detailed logic of a business rule. Complicated process flows in the system are captured in the activity diagram. Similar to a state diagram, an activity diagram also consists of activities, actions, transitions, initial and final states, and guard conditions. However, difference is state diagrams are in context of simulation while activity gives detail view of business logic.

Deployment diagram:

Deployment diagrams show the hardware for your system, the software that is installed on that hardware, and the middleware used to connect the disparate machines to one another. It shows how the hardware and software work together to run a system. In one, line its shows the deployment view of the system.

Component diagram:

The component diagram represents the high-level parts that make up the system. From .NET angle point of view, they form the “NAMESPACES”. This diagram depicts, at a high level, what components form part of the system, and how they are interrelated. Its shows the logical grouping of classes or group of other components.

See the following video on UML diagram: -

Click to get UML Training

Regards,

Get more UML training stuffs from author’s blog

C# Training: - What are different types of IIS isolation levels?

IIS has three level of isolation:-

LOW (IIS process):- In this main IIS, process, and ASP.NET application run in same process. So if any one crashes the other is also affected. Example let us say (well this is not possible) I have hosted yahoo, hotmail .amazon and goggle on a single PC. So all application and the IIS process runs on the same process. In case any website crashes, it affects everyone.

                 image

                                   Figure: - LOW IIS process scenario

Medium (Pooled):- In Medium pooled scenario, the IIS, and web application run in different process. Therefore, in this case there are two processes process1 and process2. In process1, the IIS process is running and in process2, we have all Web application running.

                    image

                                         Figure: - Medium pooled scenario

High (Isolated):-In high isolated scenario every process is running is there own process. In below figure there are five processes and every one handling individual application. This consumes heavy memory but has highest reliability.

                image

                                          Figure: - High isolation scenario

See the following video on ASP.NET4.0 Redirectpermanent: -

Click to get Most asked c# interview questions

Regards,

Get more C# training stuffs from author’s blog

ASP.Net Interview questions: - What is the difference between ‘Server. Transfer’ and ‘response.Redirect’?

Following are the major differences between them:-

‘Response. Redirect’ sends message to the browser saying it to move to some different page, while server. Transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in ‘server. Transfer’ there is no round trip while ‘response. Redirect’ has a round trip and hence puts a load on server.

Using ‘Server. Transfer’ you cannot redirect to a different from the server itself. Example if your server is www.yahoo.com you cannot use server. Transfer to move to www.microsoft.com but yes, you can move to www.yahoo.com/travels, i.e. with in websites. Cross server redirect is possible only by using Response. Redirect.

With ‘server. Transfer’ you can preserve your information. It has a parameter called as “preserveForm”.Therefore, the existing query string etc. will be able in the calling page.

If you are navigating within the same website use “Server. Transfer” or else go for “response.Redirect ()”

See the following video on ASP.NET4.0: -

Click for more ASP.NET interview questions

Regards,

Visit for more Authors’ blog on ASP.NET interview questions

ASP.NET interview questions: - Difference between ASP and ASP.NET?

This is the most practical oriented ASP.NET Interview Questions which may be asked during the Interview by the Interviewer.

ASP.NET new feature supports are as follows:-

Better Language Support

  • New ADO.NET Concepts have been implemented.
  • ASP.NET supports full language (C#, VB.NET, C++) and not simple scripting like VBSCRIPT…

Better controls than ASP

  • ASP.NET covers large set’s of HTML controls..
  • Better Display grid like Data grid, Repeater and datalist.Many of the display grid havpaging support.

Controls have events support

  • All ASP.NET controls support events.
  • Load, Click, and Change events handled by code makes coding much simpler and much better organized.

Compiled Code

ASP.NET supports forms-based user authentication, including cookie management and automatic redirecting of unauthorized logins. (You can still do your custom login page and custom user checking).

Better Authentication Support

ASP.NET supports forms-based user authentication, including cookie management and automatic redirecting of unauthorized logins. (You can still do your custom login page and custom user checking).

User Accounts and Roles

ASP.NET allows for user accounts and roles, to give each user (with a given role) access to different server code and executables.

High Scalability

  • Much has been done with ASP.NET to provide greater scalability.
  • Server to server communication has been greatly enhanced, making it possible to scale an application over several servers. One example of this is the ability to run XML parsers, XSL transformations, and even resource hungry session objects on other servers.

Easy Configuration

  • Configuration of ASP.NET is done with plain text files.
  • Configuration files can be uploaded or changed while the application is running. No need to restart the server. No more metabase or registry puzzle.

Easy Deployment

No more server restart to deploy or replace compiled code. ASP.NET simply redirects all new requests to the new code.

See the following video on ASP.NET for importance of session and view state: -


Click for more ASP.NET interview questions

Regards,

Visit for more Authors’ blog on ASP.NET interview questions

ASP.NET interview questions: - Can you explain in brief how the ASP.NET authentication process works?

ASP.NET does not run by itself, it runs inside the process of IIS. Therefore, there are two authentication layers, which exist in ASP.NET system. First authentication happens at the IIS level and then at the ASP.NET level depending on the WEB.CONFIG file.

Below is how the whole process works:-

  • IIS first checks to make sure the incoming request comes from an IP address that is allowed access to the domain. If not it denies the request.
  • Next IIS performs its own user authentication if it is configured to do so. By default IIS allows anonymous access, so requests are automatically authenticated, but you can change this default on a per – application basis with in IIS.
  • If the request is passed to ASP.NET with an authenticated user, ASP.net checks to see whether impersonation is enabled. If impersonation is enabled, ASP.net acts as though it were the authenticated user. If not ASP.net acts with its own configured account.
  • Finally, the identity from step 3 is used to request resources from the operating system. If ASP.net authentication can obtain all the necessary resources it grants the users request otherwise it is denied. Resources can include much more than just the ASP.net page itself you can also use .NET’s code access security features to extend this authorization step to disk files, Registry keys and other resources.

See the following video on ASP.NET Forms authentication by using session hijack: -

Click for more ASP.NET interview questions

Regards,

Visit for more Author’s blog on ASP.NET interview questions

ASP.NET interview questions: - What are benefits and limitations of using Query Strings?

A simple but most frequently asked ASP.NET interview question.

A query string is information sent to the server appended to the end of a page URL.

Following are the benefits of using query string for state management:-

  • No server resources are required. The query string containing in the HTTP requests for a specific URL.
  • All browsers support query strings.

Following are limitations of query string:-

  • Query string data is directly visible to user thus leading to security problems.
  • Most browsers and client devices impose a 255-character limit on URL length.

See the following video on ASP.NET for importance of session and viewstate: -

Explore for more ASP.NET interview questions tutorials.

Regards,

From Author’s blog see other blog links ASP.NET interview questions

ASP.NET Interview questions: - What is the use of session and viewstate in ASP.NET?

HTTP is a stateless protocol , session and viewstate help you to maintain states between request and response.

For more information see the below video.

Click for more ASP.NET Interview questions

Regards,

Visit for more authors’ blog on ASP.NET Interview questions

ASP.NET interview questions: - What is the difference between trace and debug in ASP.NET?

There is also a fundamental difference in thinking when we want to use trace and when want to debug. Tracing is a process about getting information regarding program’s execution. On the other hand debugging is about finding errors in the code.

Debug and trace enables you to monitor the application for errors and exception without VS. NET IDE.

In Debug mode compiler inserts some debugging code inside the executable. As the debugging code is the part of the executable they run on the same thread where the code runs and they do not given you the exact efficiency of the code ( as they run on the same thread). So for every full executable DLL you will see a debug file also as shown in figure ‘Debug Mode’.

      

                                                   Figure: - Debug mode

Trace works in both debug as well as release mode. The main advantage of using trace over debug is to do performance analysis which cannot be done by debug. Trace runs on a different thread thus it does not impact the main code thread.

See the following video for how to Skip debugging in ASP. NET: -

Click for more ASP. NET Interview questions

Regards,

Visit for more authors’ blog on ASP. NET Interview questions

ASP.NET Interview Questions: - What is Post Cache substitution?

This is one of the asked ASP.Net Interview Questions during the Interview by the Interviewer.

Post cache substitution is used when we want to cache the whole page but also need some dynamic region inside that cached page. Some examples like QuoteoftheDay, RandomPhotos, and AdRotator etc. are examples where we can implement Post Cache Substitution.

Post-cache substitution can be achieved by two means:

  • Call the new Response.WriteSubstitution method, passing it a reference to the desired substitution method callback.
  • Add a <asp:Substitution> control to the page at the desired location, and set its methodName attribute to the name of the callback method.

      

                           Figure: - “Writesubstitution” in action

You can see we have a static function here “GetDateToString()”. We pass the response substitution callback to the “WriteSubstitution” method. So now, when ASP.NET page framework retrieves the cached page, it automatically triggers your callback method to get the dynamic content. It then inserts your content into the cached HTML of the page. Even if your page has not been cached yet (for example, it’s being rendered for the first time), ASP.NET still calls your callback in the same way to get the dynamic content. So you create a method that generates some dynamic content, and by doing so you guarantee that your method is always called, and it’s content is never cached.

Ok the above example was by using “WriteSubstitution” now lets try to see how we can do by using “<asp:Substitution>” control. You can get the “<asp:Substitution>” control from the editor toolbox.

                

                                  Figure: - Substitution Control

            

                                     Figure: - Substitution in Action

Below is a sample code that shows how substitution control works. We have ASPX code at the right hand side and class code at the behind code at the left hand side. We need to provide the method name in the “methodname” attribute of the substitution control.

View following video on Web.config transformation in ASP .Net: -

Learn more on ASP.NET interview questions

Regards,

From more on author’s blog related to ASP.NET interview questions click and visit.

3 Important Concepts: - Association, Aggregation and Composition.

Introduction

Extracting real world relationships from requirement

Requirement 1 (The IS A relationship)

Requirement 2 (The Using relationship: - Association)

Requirement 3 (The Using relationship with Parent: - Aggregation)

Requirement 4 and 5 (The Deathrelationship: - Composition)

Putting things together

The source code

Summarizing

Video on Association, Aggregation and Composition

Introduction

In this article we will try to understand 3 important concepts association, aggregation and composition.

We will also try to understand in what kind of scenarios do we need them. These 3 concepts have really confused lots of developers and in this article my attempt would be to present the concepts in a simplified manner with some real world examples.

Extracting real world relationships from requirement

The whole point of OOP is that your code replicates the real world object, thus making your code readable and maintainable. The time we say real world, real world have relationships. Let’s consider the simple requirement listed below:-

  1. Manager is anemployee of XYZ limited corporation.
  2. Manager uses a swipe card to enter XYZ premises.
  3. Manager has workers who work under him.
  4. Manager has the responsibility of ensuring that the project is successful.
  5. Manager’s salary will be judged based on project success.

If you flesh out the above 5 point requirement we can easily visualize 4 relationships:-

  • Inheritance
  • Aggregation
  • Association
  • Composition

Let’s understand them one by one.

Requirement 1 (The IS A relationship)

If you see the first requirement (Manager is an employee of XYZ limited corporation) it’s a parent child relationship or inheritance relationship. The sentence above specifies that Manager is a type of employee, in other words we will have two classes one the parent class “Employee” and the other a child class “Manager” which will inherit from “Employee” class.

Note: -The scope of this article is only limited to aggregation, association and composition. So we will not discuss inheritancein this article as its pretty straight forward and I am sure you can get1000 of articles on the net which will help you in understanding the same.

Requirement 2 (The Using relationship: - Association)

The requirement 2 is an interesting requirement (Manager uses a swipe card to enter XYZ premises). In this requirement the manager object and swipe card object use each other but they have their own object life time. In other words they can exist without each other. The most important point in this relationship is that there is no single owner.

image

The above diagram shows howthe “SwipeCard” class uses the “Manager” class and the “Manager” class uses the “SwipeCard” class. You can also see how we can create the object of the “Manager” class and “SwipeCard” independently and they can have their own object life time.

This relationship is called as the “Association” relationship.

Requirement 3 (The Using relationship with Parent: - Aggregation)

The third requirement from our list (Manager has workers who work under him) denotes the same type ofrelationship like association but with a difference that one of them is an owner. So as per the requirement the “Manager” object will own “Workers” object.

The child “Worker” objects can not belong to any other objects. For instance the “Worker” object cannot belong to the “SwipeCard” object.

But But….the “Worker” object can have his own life time which is completely disconnected from the “Manager” object. Looking from a different perspective it means that if the “Manager” object is deleted the “Worker” object does not die.

This relationship is termed as the “Aggregation” relationship.

image

Requirement 4 and 5 (The Deathrelationship: - Composition)

The last two requirements are actually logically one. If you read closely both the requirements which are as follows:-

  1. Manager has the responsibility of ensuring that the project is successful.
  2. Manager’s salary will be judged based on project success.

Below is the conclusion from analyzing the above requirements:-

  1. Manager and the project objects are dependent on each other.
  2. The lifetimes of both the objects are same. In other words the project will not be successful if the manager is not good and manager will not get good increments if project has issues.

Below is how the class formation will look like. You can also see when I go to create the project object it needs the manager object.

image

This relationship is termed as the composition relationship. In this relationship both objects are heavily dependent on each other. In other words if goes for garbage collection the other also has to garbage collected , or putting from a different perspective the life time of the objects are same. That’s why I have put in the heading “Death” relationship.

Putting things together

Below is a visual representation of how the relationships have emerged from the requirements.

image

The source code

You can also download source code for this article

Summarizing

To avoid confusion hence forth in these 3 terms I have put forward a table below which will help us compare them from 3 angles owner , life time and child object.

image

Video on Association, Aggregation and Composition

I have also added a video in case you do not want to read this long article.

Just a note I have recorded around 500 videos, do have once a look at my videos on .NET, OOP, SQL Server, WCF, Silver light , LINQ , VSTS, Share Point, Design patterns , UML and lot more.

Visit to get more stuff on important Dotnet interview questions

Regards,

Also visit for more author’s other blogs on Most asked .NET interview questions

.NET interview questions: - How will you elaborate project life cycle?

This is basic of .NET interview questions which are mostly asked to 1 year experience and above candidates.

So here is a simplified answer we have put in front with a diagram so that you can learn in a more easier manner.

image

                       Figure: - Life cycle of a project

There are five stages of any project initiating, planning, executing, controlling, and closeout. These are general phases and change according to domain. Example when writing a book we will have the following mappings initiating (contacting publishers, getting copy right etc), planning (Table of contents of book, Number of chapters, tool to use, chapter wise deadlines etc), executing (Actually writing the book), controlling (proof reading, language checks, page alignments etc), and closeout (Finally printing and on the shelf for sale). Therefore, this classification is at very broader level, for software development the above figure shows the mapping.

During Software project management interview, expected answer is requirement phase, design phase, coding phase, testing phase, and project closure. But you can just impress the answer by giving a general answer and then showing the mapping.

Also see a question for differences between Abstraction and Encapsulation based on OOPS as follows: -

Learn more on interview questions and answers for .NET

Regards,

From more on author’s blog related to Most asked .NET interview questions click and visit.

4 real time use of Partial classes and partial methods.

Introduction
Fundamentals of partial classes
Fundamentals of partial methods
Use number 1:- ASP.NET auto generated code
Use number 2:- LINQ and Entity framework
Use number 3:- Better maintenance by compacting large classes
Use number 4:- Multiple people working on the same class

Introduction

Recently I was hunting about partial classes and the real time use of the same. Many of those postings found on google talked about the concept of partial classes and partial methods, but in what scenarios to use them very few highlighted.

In this article we will first start with fundamentals of partial classes and methods and then discuss the 4 real time use of the same.

I have also created a video of the same here where I have discussed about partial classes and shown the real time use of the same.

Fundamentals of partial classes

A partial class allows a single class to be divided in to two separate physical files. During compile time these files get compiled in to single class. For instance you can see in the below figure we have the customer class divided in to two different files “customer1.cs” and “customer2.cs”.

During compilation these files gets compiled in to single class internally. So when you create an object of the customer class you will be able to see methods lying in both the physical files. For instance you can see “Add” method belongs to “customer1.cs” and “Delete” method belongs to “customer2.cs” , but when the customer object is created we can see both “Add” and “Delete” methods.

image

Fundamentals of partial methods

There is one more important concept in partial classes called as partial methods. Partial methods helps us to define a method definition in one of the physical files and we can implement that method in the other physical files as shown in the below figure.

In the below figure you can see we have defined “Validate” method in “Customer1.cs” and this validate method is implemented in “Customer2.cs”. Please note the partial keywords attached to both of these methods.

image

Use number 1:- ASP.NET auto generated code

The biggest use of partial classes is in technologies where there is code generation. Microsoft team themselves use partial classes in ASP.NET, LINQ and EF code generation. For instance when we look at ASP.NET there are two parts one is the auto generated code of a page and the other is behind code where you write your custom logic.

The custom logic is written in the “.aspx.cs” file while the auto generated logic is in “.aspx.designer.cs” file as shown in the below figure.

image

As a developer you would like the auto generated code to do his work i.e. generate code when you drag and drop a button the ASP.NET designer.

image

Below is how the code snippet of the auto generated code looks like.

public partial class WebForm1 {
        
        /// 
        /// form1 control.
        /// 
        /// 
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// 
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
        
        /// 
        /// Button1 control.
        /// 
        /// 
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// 
        protected global::System.Web.UI.WebControls.Button Button1;
        
        /// 
        /// Label1 control.
        /// 
        /// 
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// 
        protected global::System.Web.UI.WebControls.Label Label1;
    }

At the same time you would also like to customize the code in some other file so that the auto generation part is not disturbed. For the same ASP.NET provides the “.aspx.cs” file which is a partial class where in you can go put your own custom logic.

public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Your custom logic
        }
    }

This is only possible when the class is split in two physical files but united via the partial keyword. So if you see any ASP.NET behind code class files it’s marked by the word partial.

So by using the partial keyword in ASP.NET the Microsoft team has made VS and developer work side by side thus not fiddling with each other’s code and thus increasing productivity.

image

Use number 2:- LINQ and Entity framework

LINQ and EF also use partial classes and methods heavily because of the auto generation nature of these technologies. So when you drag tables in these framework they create auto generated classes as shown in the below figure.

In the below figure you can see how the auto generated code has partial classes and partial methods.

image

image

The partial methods later can be extended to put custom logic. For instance you can see in the below code for the above autogenerated class “tblCustomer” we have used partial methods to override the “OnCustomerCodeChanged” event to ensure that customer code is not more than 8 length.

public partial class tblCustomer
    {
        partial void OnCustomerCodeChanged()
        {
            if (_CustomerCode.Length > 8)
            {
                throw new Exception("Customer code can not be greater than 8");
            }
        }
    }

So by using partial classes and partial methods, LINQ and EF framework keep auto generating classes and by using partial methods we can customize the class with our own logic.

Use number 3:- Better maintenance by compacting large classes

The other important use of partial classes is for better maintenance of the project. If you have large classes with lots of methods as shown in the below figure , it’s a bit pain to maintain those classes.

image

By using partial classes you can split them in to physical files as shown in the below figure thus making your project better and easy to maintain.

image

Use number 4:- Multiple people working on the same class

image

The last and final real time I see of partial classes is when we want simultaneously two developers to work in the same class. I agree this can be a very rare use as there are better options like using a version control software like TFS or Sub version, but in case you want something quick and local this option is not bad at all.

You can also watch my 500 videos on different technologies like .NET, C#, Silverlight, Azure, VSTS, WCF, WPF, WWF, Share Point, design patterns, UML and lots more.

For other author’s blog on Dotnet interview questions and answers articles.