Wednesday, December 8, 2010

32 important .net interview questions

32 important.net interview questions


When interviewer starts with .net basic questions then following are most
likey asked important questions during an interview. So always prepare and
revise it when ever you go for the.net interview
Normally the .net interviewer starts with.....


What is an IL?
What is a CLR?
What is CTS?
What is a CLS (Common Language Specification)?
What is a Managed Code?
What is a Assembly?
What are the different types of Assembly?
What is NameSpace?
What is Difference between NameSpace and Assembly?
If you want to view an Assembly how do you go about it?
What is Manifest?
Where is version information stored of an assembly?
Is versioning applicable to private assemblies?
What is GAC?
What is the concept of strong names?
How to add and remove an assembly from GAC?
What is Delay signing?
What is garbage collection?
Can we force garbage collector to run?
What is reflection?
What are different types of JIT?
What are Value types and Reference types?
What is concept of Boxing and Unboxing ?
What is the difference between VB.NET and C#?
What is the difference between System exceptions and Application
exceptions?

What is CODE Access security?
What is a satellite assembly?
How to prevent my .NET DLL to be decompiled?
What is the difference between Convert.toString and .toString () method?
What is Native Image Generator (Ngen.exe)?
If we have two version of same assembly in GAC how do we make a choice?
What is CodeDom?
Really friends having answered to .net interview questions is one thing and answering with the proper right key word will help you to impress in front of the interviewer.

Tuesday, December 7, 2010

ASP.NET Interview questions Caching , Application and ASP.NET page lifecycle - Part 1 ( 5 Questions ).

ASP.NET Interview questions Caching , Application and ASP.NET page life
cycle - Part 1 ( 5 Questions ).

Below are Most important ASP.NET interview questions from caching aspect
during .NET Interviews .
Day before yesterday I was at Mumbai Seepz giving a C# interview and below are some questions which where asked from ASP.NET aspect.

What are the various ways of doing caching in ASP.NET ?You can cache by using output cache directive , cache object and application object.
The next thing the interviewer asked was regarding cache and application object.
What's the difference between cache and application object ?In cache object you can define dependency properties , in application object you can not. In other words when the data which is cached changes even the cache object gets refreshed , but this is not the case of application object. You need to do a pull to refresh the data.This is a 100% sure question , how does ASP.NET page life cycle work ?.
What are the different events which occur in ASP.NET page life cycle ?
Init , load , validate , event and render.
Remember SILVER ( Init , load , validate , event and render).
What are HttpHandlers and HttpModules ?
Both of these entities have one common goal , i.e. intercepting ASP.NET request and performing some operation on the request before it reaches the main object.
But they way they intercept the request are different. HttpHandler intercepts the request using file extensions while HttpModule intercepts the request using Http events.
You can refer ASP.NET page life cycle article here for details.

Why do we need session variables ?Http is a stateless protocol , after every request and response it forgets its original state. Session variables helps us to remember the state after every request and response.

Well frankly I did not clear this ASP.NET interview as I failed to answer simple .NET interview questions. So i will suggest every one to go through .NET Interview questions from this link. This article is part 1 of ASP.NET interview question and answers i will be soon posting by other questions in the coming week... Happy job hunting.

By Shivprasad koirala

Monday, December 6, 2010

Most important ASP.NET Interview questions

Most importantASP.NET Interview questions


Below are Most important ASP.NET interview questions which repeat again and again in .NET Interviews .

Most important ASP.NET Interview questions and answers


What’ is the sequence in which ASP.NET events are processed?


In which event are the controls fully loaded?


How can we identify that the Page is Post Back?


How does ASP.NET maintain state in between subsequent request?


What is event bubbling? How do we assign page specific attributes?


How do we ensure viewstate is not tampered?


What is the use of @ Register directives?


What is the use of Smart Navigation property?


What is AppSetting Section in “Web.Config” file?


Where is View State information stored?


what is the use of @ Output Cache directive in ASP.NET.


How can we create custom controls in ASP.NET?


How many types of validation controls are provided by ASP.NET?


Can you explain “AutoPostBack”?


How can you enable automatic paging in Data Grid?


What is the use of “GLOBAL.ASAX” file?


What is the difference between “Web.config” and “Machine.Config”?


What is a SESSION and APPLICATION object?


What is the difference between ‘Server.Transfer’ and ‘response. Redirect’ ?


What is the difference between Authentication and authorization?


what is impersonation in ASP.NET?


Can you explain in brief how the ASP.NET authentication process works?


What are the various ways of authentication techniques in ASP.NET?


How does authorization work in ASP.NET?


What is difference between Data grid, Datalist, and repeater?


From performance point of view, how do they rate?


What is the method to customize columns in Data Grid?


How can we format data inside Data Grid?


How to decide on the design consideration to take a Data grid, data list, or
repeater?


Difference between ASP and ASP.NET?


What are major events in GLOBAL.ASAX file?


What order they are triggered?


Do session use cookies?


How can we force all the validation control to run?


How can we check if all the validation control are valid and proper?


If client side validation is enabled in your Web page, does that mean server
side code is not run.


Which JavaScript file is referenced for validating the validators at the client
side?


How to disable client side script in validators?


How can I show the entire validation error message in a message box on the
client side?


You find that one of your validations is very complicated and does not fit in
any of the validators, what will you do?


What exactly happens when ASPX page is requested from a browser?


How can we kill a user session?


How do you upload a file in ASP.NET?


How do I send email message from ASP.NET?


What are different IIS isolation levels?


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


What is the use of <%@ page aspcompat=true %> attribute?


B) Explain the differences between Server-side and Client-side code?


Can you explain Forms authentication in detail?


How do I sign out in forms authentication?


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


How to use a checkbox in a data grid?


What are the steps to create a windows service in VB.NET?


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


How do we configure “Web Garden”?


What is the main difference between Grid layout and Flow Layout?


What’s the difference between trace and debug in ASP.NET?


How do you enable tracing in on an ASP.NET page?


Which namespace is needed to implement debug and trace ?


Can you explain the concept of trace listener?


What are trace switches?

Friday, December 3, 2010

34 important ASP.NET Interview questions

34 important ASP.NET Interview questions


Below are 34 important ASP.NET interview questions which repeat again and
again in .NET Interviews .

  1. What is an application object?
  2. what is the difference between Cache object and application object?
  3. How can get access to cache object?
  4. What are dependencies in cache and types of dependencies?
  5. Can you show a simple code showing file dependency in cache?
  6. What is Cache Callback in Cache?
  7. What is scavenging?
  8. What are different types of caching using cache object of ASP.NET?
  9. How can you cache different version of same page using ASP.NET cache object?
  10. How will implement Page Fragment Caching?
  11. Can you compare ASP.NET sessions with classic ASP?
  12. Which are the various modes of storing ASP.NET session?
  13. Is Session_End event supported in all session modes? 106
  14. What are the steps to configure StateServer Mode?
  15. What are the steps to configure SQLServer mode?
  16. Where do you specify session state mode in ASP.NET?
  17. What are the other ways you can maintain state?
  18. What are benefits and Limitation of using Hidden fields?
  19. What is ViewState?
  20. Does the performance for viewstate vary according to User controls?
  21. What are benefits and Limitation of using Viewstate for state management?
  22. How can you use Hidden frames to cache client data ?
  23. What are benefits and limitations of using Hidden frames?
  24. What are benefits and limitations of using Cookies? 109
  25. What is Query String and What are benefits and limitations of using Query
    Strings?
  26. What is Absolute and Sliding expiration?
  27. What is cross page posting?
  28. How do we access viewstate value of this page in the next page ?
  29. Can we post and access view state in another application?
  30. What is SQL Cache Dependency in ASP.NET 2.0?
  31. How do we enable SQL Cache Dependency in ASP.NET 2.0?
  32. What is Post Cache substitution?
  33. Why do we need methods to be static for Post Cache substitution?
  34. Can you explain page life cycle ?

Wednesday, December 1, 2010

C# and .NET OOP (Object oriented  programming) interview questions - Abstract classes and interfaces.


C# and .NET OOP (Object oriented programming) interview questions
-
Abstract classes and interfaces.


I have yet to remember a .NET interviewer who never asked about abstract classes, interfaces and object oriented interview questions . I am putting forward questions which comes around abstract classes and interfaces again and again...Hope every one benefits.
Normally the C# interviewer starts with.....

What is abstract class ?
Abstract class is a base class or a parent class. Abstract classes can have empty abstract methods or it can have implemented methods which can be overridden by child classes.

The next question i expected
was on interfaces and yes there it comes.


What are interfaces?
Interface is a contract class with empty methods , properties and functions. Any class which implements the interface has to compulsory implement all the empty methods , functions and properties of the interface.
Now the 1000% sure
question was bound to come difference between them...



What's the difference between abstract class and interface?
There are many differences, below are some key two differences :-

  • Abstract class are base class or parent class while interfaces are
    contracts.

  • Abstract class can have some implemented methods and functions while
    interfaces methods and functions are completely empty.

  • Abstract classes are inherited while interfaces are implemented.

  • Abstract classes are used when we want to increase reusability in
    inheritance while interfaces are used to force a contract.

Can we create a object of abstract class or interface?
No we can not.
Now the practical
question..


In what scenarios will you use a abstract class and in what scenarios will
you use a interface?

If you want to increase reusability in inheritance then abstract classes are
good. If you want implement or force some methods across classes must be for
uniformity you can use a interface. So to increase reusability via inheritance
use abstract class as it is nothing but a base class and to force methods use
interfaces.
Really friends having C# experience is one thing and cracking
Dot net and C# interviews is a different ball game all together .

Monday, November 29, 2010

.NET and C# interview questionsBoxing, Unboxing, Heap, Stack, By reference and by value

.NET and C# interview questions Boxing, Unboxing, Heap, Stack, By reference and by value


Also see
Important .NET interview questions and answers part 1
Important .NET interview questions and answers part 2

Recently I went for a big IT multinational company and the interviewer grilled me in for a hour around the below concepts Boxing , Unboxing , Heap , Stack , By reference and by value. I am just putting my experience so that every one can be benefitted. The above 6 concepts are very much interlinked and asked by C# interviewers again and again. They can start from anyone of the three sections i.e. boxing / unboxing , Stack / Heap or By ref and value.

From which ever section they initiate the discussion, all interviewers touch base the above concept directly indirectly. In my particular C# interview he started first with...

What are stack's and heaps ?

Stack are like series of compartment i.e. one above another. It keeps track of your running memory needed by your application. On the other hand heap is nothing but pile of objects which are kept one above another and they can be reached any moment of time.

I knew that I had answered right but he was not expecting that answer he was expecting something else....So bang came the next question.

So what kind of data stack has and heap has ?

Both stack and heap are memory types. Stack memory are value types like integer , double , Boolean etc , while heap memory are objects and string data types.

Once I answered the above question , I was expecting the next question on what are value types and references. But he went some other route but again near to expectation ...

How is boxing and unboxing related to the above concept ?

Boxing happens when data moves from value type to reference type and unboxing happens when data moves from reference types to value types.

This leads to a small performance hit in the application.

I purposely put the last line so that he would probe further on performance and yes yes , he asked me the next question...Its my simple old trick to force the interviewer to ask question which i am good at..;-)

Why does performance decrease when boxing and unboxing happens ?

In boxing and unboxing data moves from value to reference and vice versa which needs quite a bit processing as they are different memory types all together. Due to the same there is a performance decrease when the boxing and unboxing phenomenon happens.

I knew this was becoming a in-depth discussion forum and the next question but obvious was ...

So how can we avoid boxing and unboxing ?

We can not really avoid , but where ever possible we can do two things at least :-



  • First is avoid unnecessary conversions.


  • Second use generics to avoid the conversion situation.

What are the scenarios in which boxing and unboxing happens ?

One of the common situation is when we take data in to UI object like text boxes and we need to move the data in to a value data type like integer , double etc. As the UI textboxes and controls are objects its very difficult to avoid this scenario.

Are string by val or by ref ?

They are by ref. String and objects are by ref and they are always stored in a heap. All the other data types other than these 2 are value types.

This question was unexpected...but i had my concepts clear..so.

How do stack and heap memory gets claimed back when the application exits ?.

Stack is the running memory , the byval memory , So it just gets claimed when the application exits. The by ref memory or heap memory is not claimed as soon as the application exits , but its claimed by the garbage collector routine. So the GC just spawns and claims the memory acquired by the heap.

By Shivprasad Koirala.

Thursday, October 21, 2010

CAS (Code access security) & .NET 4.0 Security model FAQ (With Full Video demonstration)

Introduction
What is CAS?

What is evidence in CAS?
What is a permission and permission set?
What is code group?
So how does CAS work on runtime?
Can we see a quick demo of CAS?
What is CASPOL.exe?
When I open a .NET 4.0 DLL/Assembly using CASPOL it throws an error?
Can you throw some more light on the security transparent model?
A demo of security transparent model can really make things clear?
What is the concept of sandboxing?
Security transparent is good when we control the code what about external DLL?
But why this change, what was the problem with CAS?
So how can we give code access after .NET 4.0 and later?
What if I still want to use CAS in .NET 4.0?
References


Introduction

Many developers understand the concept of CAS (Code access security) but very few know how to implement the same. This article will discuss and demonstrate practically all those aspects of CAS which you have ready only in theory till today.
This article first starts with the basic concepts of CAS like evidence, permission, code groups and caspol.exe. It then moves ahead to demonstrate how CAS can be implemented in real world. This article further talks about ground up changes made in .NET 4.0 for CAS. In those regards it discusses about security transparent model and sandboxing.

Bet me this article is your last chance to see CAS in actual action....enjoy.

This is a small Ebook for all my .NET friends which covers topics like WCF, WPF, WWF, Ajax, Core .NET, SQL etc you can download the same from here
or else you can catch me on my daily free training @ here

What is CAS?

Code Access security is a security model which grants or denies permission to your assembly depending on evidences like from where the code has emerged, who the publisher is? , strong names etc.

What is evidence in CAS?

When you want to execute any code in your environment you would first like to know from where the code came from. Depending from where it came from, you would then would like to give him access rights. For instance a code compiled from your own computer would have greater rights than code downloaded from the internet.

In order to know the same we need to probe the assembly / exe / dll and get evidences like who is the publisher of the code , from which site has this code from , from which zone has it come from ( internet , intranet etc) etc.

What is a permission and permission set?

Once you have gathered the evidences about the code you would like to assign permission to the code. There are various permissions which you can assign to the code like Can the code create a file, can we write to registry, can the code execute reflection, can the code open file dialog box etc.

These permissions are collect permission sets and those permission sets are allocated to the code.

What is code group?

Code groups are nothing but categories of code. These categories are defined by permissions and evidence values. When .NET code runs it’s assigned to a code group by the evidences which are collected during runtime.
For instance there are various default code groups like My computer zone , internet zone , intranet zone etc.

My computer zone code group is allocated to code who evidence says that they are assemblies which are installed on the computer and they have permission set ‘internet’ which has various permissions like file dialog , execute , user interface , printing etc.


So how does CAS work on runtime?

When the assembly runs following steps takes place:-

• Evidences are gathered about the assembly. In other words from where did this assembly come?

• Depending on evidences the assembly is assigned to a code group. In other words what rights does the assembly depending on the evidence gathered.

• Depending on code group the assembly is allocated security rights.

• Using the security rights the assembly is run with in those rights.







Can we see a quick demo of CAS?

If you want to allocate rights to an assembly we need to install the .NET configuration tool and click on trust assembly menu as shown in the below figure.

Once you trust the assembly you can adjust the trust to full trust or none.

Please do see the below complete video which explains how we can assign
permission, permission set,code group and evidence to an exe or an assembly.

What is CASPOL.exe?

It’s the core exe which is responsible to assign permission to the assembly. The .NET configuration tool is just a cover which sits on the top of caspol.exe to ease our work. CASPOL.exe commands are cryptic so the .NET configuration too is more user friendly. In case you are interested in using caspol.exe you can go to visual studio command prompt and type caspol.exe with necessary parameters.

When I open a .NET 4.0 DLL/Assembly using CASPOL it throws an error?

If you try to open a .NET 4.0 DLL in configuration wizard you will get an error as shown below.


CAS is completely deprecated in .NET 4.0, there are two big changes:-


• Granting of permission is no more dependent on the .NET CAS, it’s now the job of the host. So the host who runs the .NET DLL will define what kind of rights will the assembly have. NET Framework 4.0 comes with CAS a disabled which means all applications started via Windows Explorer or the command prompt run with full trust. Hosted .NET applications, those running inside Internet Explorer or ASP.NET, will run at the trust level granted by their host, being partially trusted.

• Security transparent model is introduced which divides a .NET code in to 3 categories Security critical, Security transparent and security safe critical.

Can you throw some more light on the security transparent model?

The security transparent model puts code in to separate boxes as per the risk associated. If you know that code can do something wrong you can box that code as ‘Security transparent’ and if you have a code which you trust you can box them in to ‘Security critical’.
By putting the above compartments you have ensured that the unsecured code (Security transparent) cannot call the secured code (Security critical). When you mark a code as security transparent, these types of code cannot call security critical code.

If for some reason the transparent code wants to call security critical code it can go via the bridge security safe critical code.

A demo of security transparent model can really make things clear?

Below is a simple video where we have created a simple code marked it as security critical and then we tried calling the same from security transparent code and we get an error.


What is the concept of sandboxing?

The next question answers the same.

Security transparent is good when we control the code what about external DLL?

The security transparent code is good when we control the code but what if get assembly which is a third party. In those situations you can use the concept of sandboxing. One of the important points to note is that CAS is deprecated and not removed completely.
So if you have third party DLL you can create your own appdomain and assign permission sets so that your 3rd party DLL runs under a control environment. Below is a simple code snippet which shows how we can do things. The below code snippet, creates an application domain, allocates permissions for execution and user interface display only.

We then try to do something funny like popping up a file brows dialog box and we end up with error as shown in the below figure.

Step1:- Create appdomain with two permission execution and UI display
using permission set class.

PermissionSet permset = new PermissionSet(PermissionState.None);
permset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
permset.AddPermission(new UIPermission(UIPermissionWindow.AllWindows));

Step 2:- Apply the above defined permission set to the newly created application domain as shown in the below code snippet.

AppDomainSetup objSetup = new AppDomainSetup();
objSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
AppDomain domain = AppDomain.CreateDomain("New domain name",
AppDomain.CurrentDomain.Evidence, objSetup, permset);

Step 3:- Create the instance and try calling the ‘ShowDialog’ function.
Interface1 i1 = (ClassLibrary1.Class1)domain.CreateInstanceAndUnwrap("ClassLibrary1",
"ClassLibrary1.Class1");
i1.ShowDialog();
If you try to execute the open dialog it will pop up an error as shown in the below code.



But why this change, what was the problem with CAS?

• First thing CAS was not easy, all those cryptic steps of creating code groups, and permission sets etc eats your energy completely.
• If you have to move the assembly to a different computer you need to do the whole rework again.

• The worst part CAS does not work on unmanaged code. I am dead sure it’s always possible you will download exe which is not written in .NET.

So how can we give code access after .NET 4.0 and later?

The best way to restrict code access is by putting restriction at the operating system level. Windows SRP (Software restriction policy) helps to achieve the same.
• Log on with an Administrator account.

• Type gpedit.msc into the Run or Search box on your Start menu, click OK, and
Group Policy will open.

• Go down to Computer Configuration > Windows Settings > Security Settings.

• Right-click on "Software Restriction Policies" and create new policies.




What if I still want to use CAS in .NET 4.0?

“<NetFx40_LegacySecurityPolicy>” configuration element lets you specify that a process or library uses CAS policy. When you activate this element, the policy and evidence overloads will work as they did in older versions of the .NET framework.

<configuration>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true"/>
</runtime>
</configuration>

http://blogs.rev-net.com/ddewinter/2010/03/02/tip-20-opting-out-of-security-changes-in-net-4-in-asp-net-and-custom-appdomains/

References

MSDN link to CAS
http://msdn.microsoft.com/en-us/library/930b76w0%28VS.90%29.aspx

What’s new in .NET 4.0 security
http://www.simple-talk.com/dotnet/.net-framework/whats-new-in-code-access-security-in-.net-framework-4.0---part-i/


CAS in .NET nice simple article
http://www.devx.com/vb2themax/article/19886/1954


Nice Q and A article explaining CAS
http://justindeveloper.wordpress.com/2010/02/09/application-security-for-developers/

5 reasons why you would use sandboxing
http://blogs.msdn.com/b/shawnfa/archive/2006/04/19/579066.aspx

Legacy CAS policy in .NET 4.0 backward compatibility
http://blogs.rev-net.com/ddewinter/2010/03/02/tip-20-opting-out-of-security-changes-in-net-4-in-asp-net-and-custom-appdomains/