Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

ASP.NET Interview Questions for Beginners and Professionals - Part 4

5.00/5 (6 votes)
21 Apr 2014CPOL5 min read 23.3K  
ASP.NET Interview Questions for Beginners and Professionals - Part 4

This is a continuation in the series of ASP.NET Interview Questions and Answers for beginners as well as professional developers. If you haven't gone through the previous ASP.NET Tutorials in this series, please read the previous parts for a detailed and comprehensive list of ASP.NET Interview Questions here.

Security is a huge area of concern, so this part of ASP.NET Interview Questions will continue with Security related questions. In the previous ASP.NET Tutorial, i.e. Part 3, we discussed about Authentication and Authorization, different authentication modes in ASP.NET.

What is Passport Authentication?

As we have discussed previously, there are three types of authentications in ASP.NET, i.e.:

  • Windows Authentication
  • Forms Authentication
  • Passport Authentication

Windows and Forms Authentications are already explained.

Passport Authentication actually validates against a centralized authentication service, i.e., Microsoft Passport Service. We don't need to implement our own custom authentication mechanism if implementing .NET Passport Single Sign-In (SSI) service.

Can you briefly explain how Passport Authentication works?

As discussed above, Passport Authentication is a central service. It just authenticates (validates the credentials), no authorization (grant or deny access to a site). So, implementing application will check for the Passport Authentication Cookie. In case of unavailability of Passport Cookie, the user is redirected to passport Sign-In page. User provides the credentials on Sign-In page, if validated, Authentication Cookie is stored on client machine and redirected to the requested page.

What are the advantages of using Passport Authentication?

Advantages of Passport Authentication are:

  • We don't need to take care of authentication mechanism ourselves, Passport SSI does this for us.
  • Single login credentials can be used to access multiple sites. Users don't need to remember separate credentials for individual site.

What is Role-based Security?

We have discussed about authentication in the above questions but another different but related concept is Authorization. Authorization is a process of granting privileges or permissions on resources to an authenticated user. So, "Role Based Security is a technique we use to implement authorization on the basis of user's roles within an organization. It's a more granular approach to grant or revoke permissions on resources through user's roles."

An example of granting or revoking permissions in configuration file using Windows built-in groups is as follows:

XML
<authorization >
    <allow roles="MyDomain1\Administrators" / >   < !– Allow Admin of this domain  >
    <deny users="*"  / >                                          < !– Deny anyone else.  >
</authorization >

What are the different Security Controls in ASP.NET?

ASP.NET provides several security controls which are actually Web Server controls. You can find those in your Visual Studio Toolbox.

Login Control

In almost every application, we need to take user credentials on a typical login page. Login control provides the same standard functionality and reduces the effort for building it from scratch.

LoginName

After a user successfully logged in to an application, we normally display his/her username to top right or some other place on the page. Now, this functionality is provided by LoginName control.

LoginView Control

LoginView control displays different view for different users. Using AnonymousTemplate and LoggedInTemplate, different information can be presented to different users.

LoginStatus Control

LoginStatus control implies whether a user is authenticated or not. For an unauthenticated user, it displays a link to login page. On the other hand, for authenticated user, a logout link is displayed.

LoginRecovery Control

Password recovery is another important functionality simplified through PasswordRecovery control. It sends an email with login credentials to registered user email.

What is Code-Access Security (CAS)?

In one of the above ASP.NET security related interview questions, we discussed about Role Based Security that restricts access to resources on the basis of user's role. CAS (Code Access Security) is entirely a different concept. It's .NET CLR's security system that restricts the code to perform an unwanted task by applying security policies. Using CAS (Code Access Security), we can restrict what our code can do and also what code can call our code?

What are the key functions of Code Access Security?

As per documentation, key functions of Code Access Security are (straight from MSDN):

  • Defines permissions and permission sets that represent the right to access various system resources.
  • Enables code to demand that its callers have specific permissions.
  • Enables code to demand that its callers possess a digital signature, thus allowing only callers from a particular organization or site to call the protected code.
  • Enforces restrictions on code at run time by comparing the granted permissions of every caller on the call stack to the permissions that callers must have.

What .NET Tool can be used to Enable/Disable CAS?

Code Access Security Tool (Caspol.exe) can be used to turn Code Access Security ON or OFF as follows:

  • caspol -security on
  • caspol -security off

We can also list all code groups using the following command:

  • caspol -listgroups

What is Impersonation in ASP.NET?

Impersonation is an act of a user to pretend to be another user. By default, ASP.NET executes application code using the same user account as that of ASP.NET process, i.e., Network Service. But with impersonation enabled, it executes code with the Windows identity of the user making the request.

For example, if a user 'user1' logged in and IIS is setup to run as Network Service. If 'user1' calls a piece of code on another computer (may be a web service call), the other computer will see the IIS user instead of 'user1'. But we can enable impersonation to allow 'user1' to access the web service using its Windows identity instead of Network Service.

How to configure Impersonation in ASP.NET?

By default, impersonation is disabled in ASP.NET. Impersonation can be enabled/disabled as follows:

XML
</configuration>
     <system.web>
         <identity impersonate="true"/> <! -- To disable set impersonate="false" -->
      </system.web>
</configuration>

Impersonate a specific user account as:

XML
<identity impersonate="true" userName="user" password="pwd" />

On completing Part 4 of this ASP.NET Interview Questions and Answers series, we have completed major questions on ASP.NET Security. Hopefully, this series will be beneficial in terms of preparing an ASP.NET Interview.

Previous <<< ASP.NET Interview Questions Part 3

Other Recommended Articles

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)