ASP-NET-Interview-Questions-and-Answers-LearnoVita

ASP.NET Interview Questions and Answers

Last updated on 27th Sep 2020, Blog, Interview Question

About author

Vikram ( (Sr Project Manager ) )

He is Highly Experienced in Respective Technical Domain with 6+ Years, Also He is a Respective Technical Trainer for Past 5 Years & Share's This Important Articles For us.

(5.0) | 16547 Ratings 621

1.What is MVC (Model View Controller)

Ans:

MVC is a web application framework which employs a pattern for developing a web application. It divides an application into three separate components, Model-View-Controller.

The View is responsible for user interface Model represents the real world object/business entity and encapsulates properties and behaviour.

The Controller manages a user request and handles an appropriate model to be translated into an appropriate view.

2.What is the difference between ASP.NET Core and ASP.NET MVC 5

Ans:

ASP.NET Core is a lean and composable framework for building web and cloud applications. ASP.NET Core is the fully open source.

Also, ASP.NET Core is cross-platform. We can develop ASP.NET Core web apps against the .NET core and run in either Windows or Linux or Mac.

Also, we can do develop in Windows OS, Linux, Mac using Visual Studio Code or any other code editors.

3.In Which Assembly MVC Framework Is Defined?

Ans:

The MVC framework is defined in System.Web.Mvc.

4.What are the advantages of MVC

Ans:

MVC provides separation of concern. It means we divide an application into Model, Control and View which helps to maintain our application. Each module is independent of each other which helps in reusability, maintenance and TTD (test-driven development).

5. What are the new features added in version MVC5?

Ans:

OSX and Linux Support Cloud Optimization Unification of MVC and Web API Controllers Self Hosting Tag Helpers Dependency Injection Framework

6. What are the different return types of a controller action method?

Ans:

ViewResult (View): It is the most common and used to return a webpage from an action method.

PartialviewResult (Partial view): This return type forms part of another view.

RedirectResult (Redirect): This return type is used to redirect to any other controller where the result could be processed further.

RedirectToRouteResult (RedirectToAction, RedirectToRoute): To redirect to any other action method.

ContentResult (Content): To only returns information such as content type as text/plain.

jsonResult (Json): This return type is used when we want to return a JSON (JavaScript Object Notation) message.

javascriptResult (javascript): This return type is used to return JavaScript code. the code then gets processed in the browser.

FileResult (File): This return type is used to send a file in binary format.

7. Page life cycle of MVC?

Ans:

App initialization Routing Instantiate and execute controller Locate and invoke controller action Instantiate and render a view.

8. Can you explain the Razor View Engine?

Ans:

Razor is a templating engine. It allows us to generate output like HTML. ASP.NET MVC has implemented a view engine that allows us to use Razor inside of an MVC application to produce HTML. The idea behind Razor was to provide an optimized and minimal syntax for HTML generation using a code-focused templating approach.

  • @{ViewBag.Message = “Part1”;}
  • <div class=”heading”> <h3><em>@Model.ArticleTitle</em> </h3>    

9. What is meant by Separation of Concerns ?

Ans:

It means separating a program into several modules to minimise overlapping of functionality and dependency. This greatly helps to facilitate maintenance and updates for the program.

10. What is a Controller?

Ans:

A controller is a class. This class is the entry point for the request. A controller takes the request and connects the proper business logic and Model to prepare a response and returns it in the form of a View for User.

11. What is a ViewModel?

Ans:

ViewModel is a class. It precisely binds to strongly typed View. When Validations are applied, It helps to reduce errors and perform better testing.

12. Can you explain unrobustive Javascript

Ans:

Separation of HTML and JavaScript into separate files. Graceful degradation: If javascript is disabled or browser is not able to process javascript for any reason, important parts of the page still work. In simple terms, Onrobustive Javascript doesn’t get in the way of other code in the program/webpage. It is more of JavaScript techniques and coding style.

13. How do add JavaScript inside Razor View (inline)?

Ans:

To include a JavaScript function, it is as simple as including a “script” tag and defines the function inside the script block.

14. How to add Layout Section for the script

Ans:

A section can be added in the MVC Layout page using @RenderSection() directive. For example, we can define a section in Layout page under the tag for scripts

  • <head>
  • @RenderSection(“scripts”, required: false)
  • </head>

Now add a section name scripts using @section directive in the content view.

Subscribe For Free Demo
[contact-form-7 404 "Not Found"]

15. How To Handle 404 At Application Level In ASP.NET MVC?

Ans:

web.config

  •   responseMode=”ExecuteURL”path=”/Error/PageNotFound”
  • </httpErrors>
  • </system.webServer>
  • ErrorController
  • {
  • public ActionResult PageNotFound()
  • {
  • Response.StatusCode = 404;
  • return View();
  • }
  • }

16. What Is JSON Binding?

Ans:

JavaScript Object Notation (JSON) binding provides support via JsonValueProviderFactory.

It enables action methods to send and receive JSON-formatted text.

It also enables action methods to model-bind the JSON text to parameters of action methods.

  • var person = getPerson();
  • var json = $.toJSON(person);
  • $.ajax(
  • {
  • data: json,
  • contentType: ‘application/json; charset=utf-8’,
  • success: function (data) {
  • // get the result and do some magic with it
  • var message = data.Message;
  • $(“#resultMessage”).html(message);
  • }
  • });

17. What Is Bundle.Config In ASP.NET 4.5?

Ans:

As of Asp.Net MVC4, a standard ASP.NET MVC app has a file named BundleConfig.cs in the App_Start folder, by default.

It is a way to reduce the number of server requests that the browser needs to make to get all of these resource files.

Each time a browser has to load a resource, it has to make a separate HTTP(S) request to the server.

Server requests can greatly affect the page load speed which is negative for SEO and page rankings in search engines result in pages (SERPs).

BundleConfig is used to register the bundles by the bundling together and minification of common type of resources like script (.js) and style (css) files.

  • public class BundleConfig
  • {
  • public static void RegisterBundles(BundleCollection bundles)
  • {
  • bundles.Add(new ScriptBundle(“~/bundles/bootstrap”).Include(
  • “~/Scripts/bootstrap.js”,
  • “~/Scripts/respond.js”));
  • bundles.Add(new StyleBundle(“~/Content/css”).Include(
  •  “~/Content/bootstrap.css”,
  • “~/Content/site.css”));
  • }
  • }

How To: Use and Add BundleConfig


Read More about: Bundling and Minification

18. How Is Routing Handled In Asp.Net MVC?

Ans:

Routing in ASP.NET enables you to use URLs without mapping them to physical files in a Web application.

It has several advantages:

  • We can use URLs that are descriptive of the user’s action.
  •  As Urls are not linked to any physical file in an application, we have the freedom to return a response which serves the purpose and update when needs change.
  •  We can use patterns to match requests, without including the names of those files in the URL

A routing table is enabled in your application’s Web configuration file (Web.config file) by default.

  • public class MvcApplication : System.Web.HttpApplication
  • {
  • public static void RegisterRoutes(RouteCollection routes)
  • {
  • routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
  • routes.MapRoute(
  • “{controller}/{action}/{id}”,   
  • }
  • protected void Application_Start()
  • {
  • RegisterRoutes(RouteTable.Routes);
  • }
  • }

19. What Is ViewBag In Asp.Net MVC?

Ans:

ViewBag property allows you to share values from a controller to the view.

  • ViewBag.Title = “Put your page title here”;
  • ViewBag.Description = “Put your page description here”;
  • ViewBag.UserNow = new User()
  • {
  • Name = “Your Name”,
  • ID = 4,
  • };
  • To use these values in view, we need to use the same property names.
  • <h3>@ViewBag.Title</h3>
  • <p>@ViewBag.Description</p>
  • <p>Name: @iewBag.Name>
  • <p>ID:  @ViewBag.ID>

20. What Is ViewData In Asp.Net MVC?

Ans:

ViewData is similar to ViewBag. It is a dictionary which can hold key-value pairs where each key must be a string.

ViewData only transfers data only one way, from the controller to view. It is valid only during the lifetime of a request.

In Controller

  • public ActionResult Index()  
  • {  
  • ViewData[“Company”] = “Quoracreative”;    
  • return View();  
  • }  
  • In View
  • <h2>Company Name: </h2> @ViewData[“Company”]    

21. What Is TempData In Asp.Net MVC?

Ans:

TempData can be used to store temporary data which can be used in the subsequent request only.

Use of TempData should be limited to non-sensitive data only.

It is a dictionary which can hold key-value pairs.

TempData can be used to transfer data from one action method to another action method.

  • public ActionResult Action1()
  • {
  • TempData[“CompanyName”] = “Quoracreative”;
  • return View();
  • }
  • public ActionResult Action2()
  • {
  • if(TempData.ContainsKey(“CompanyName”))
  • string CompanyName = TempData[“CompanyName”].ToString();    
  • }

22. What Is a Layout Page In Asp.Net MVC?

Ans:

In an ASP.NET MVC application, a Layout is a view which contains common UI parts, so that we don’t have to rewrite the same code over and over again in several pages.

23. What common UI Can Be Added To A Layout Page?

Ans:

A Layout page can contain the common code necessary across multiple pages such as but not limited to:

  • Logo
  • Headers Section
  • Menus
  • Footer Sections
  • Resource links like Scripts and Style Sheets
  • Meta Tags

24. What Is .Glimpse in MVC?

Ans:

Glimpse is a web debugging and diagnostics tool troubleshoot what’s happening inside of your ASP.NET MVC 5.0 application routes.

Glimpse is an open source and is a client-side debugger.

Glimpse is a NuGet package. It provides detailed performance, is fast, super-light and provides a visual display for several performance matrices.

25. How Do We Link CSS Files In Razor Views?

Ans:

Just as in any HTML page you can use the standard syntax:

  • <link rel=”StyleSheet” href=”/@Href(~Content/Site.css”)” type=”text/css”/>

26. What Are PartialViews In Asp.Net MVC?

Ans:

Partialview help with re-usability.

Partial views can be used in a similar way like UserControls.

Partial views can be shared with multiple views.

Partial Views can be rendered in following to ways:

  • Html.Partial()
  • Html.RenderPartial()

27. What Route Constraints And They Implemented?

Ans:

1. By using regular expressions:

Regular Expressions can be used to implement route constraints such as restricting the browser requests to match a particular route.

Say you only want to match URLs that contain an integer productId:

  • routes.MapRoute(“Product”,
  • “Product/{productId}”,
  • new {controller=”Product”, action=”Details”},
  • new {productId = @”\d+” }
  •  );
  • The regular expression \d+ matches one or more integers.

Following would match:

  • /Product/3
  • /Product/8999

28. By implementing the IRouteConstraint Interface:

Ans:

You can implement a route constraint by implementing the IRouteConstraint interface like follows:

  • using System.Web;
  • using System.Web.Routing;
  • namespace MvcApplication1.Constraints
  • {
  • public class LocalhostConstraint : IRouteConstraint
  • {
  • public bool Match
  • (
  • HttpContextBase httpContext, 
  • Route route, 
  • RouteValueDictionary values, 
  • RouteDirection routeDirection
  •  )
  • {
  • return httpContext.Request.IsLocal;
  • }
  • }
  • }

29. Explain Components Of A Route:

Ans:

Route Name: A name to distinguish route.

Pattern To Match: What to match.

Defaults: First Load, controller, action and any parameters

30. Are Views Shareable with Multiple Controllers?

Ans:

You can directly return a different view in the same folder:

return View(“NameOfView”, Model);

Or you can make a partial view, put the view in the “Shared” folder and can return like:

return PartialView(“PartialViewName”, Model);

If the view is in different folder folder then, use absolute path:

  • return View(“~/Views/FolderName/ViewName.aspx”);

31. What Is Scaffolding In Asp.Net MVC Application?

Ans:

ASP.NET Scaffolding is a framework for code generation for ASP.NET Web applications. You add scaffolding to your project to quickly add code standard code for a standard operation that interacts with data models.

Scaffolding can be used to generate the Controllers, Model and Views to create, read, update, and delete (CRUD) operations.

Following are the types of scaffoldings:

  • Empty
  • Create
  • Delete
  • Details
  • Edit
  • List

32. What Is RouteConfig.cs In Asp.Net MVC?

Ans:

A Route defines the URL pattern and the information on how to handle it. Pre-configured routes are stored in RouteTable and are used the by Routing engine to determine appropriate handler class or file.

Routing can help define user-friendly URL(s) which are useful for Search Engine Optimization (SEO).

You provide routing information in RouteConfig.cs file:

  • public class RouteConfig
  • {
  •  public static void RegisterRoutes(RouteCollection routes)
  • {
  • routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
  • name: “Default”,
  • url: “{controller}/{action}/{id}”,
  • defaults: new { controller = “Funcionario”, action = “AdicionarFuncionario”, id = UrlParameter.Optional }
  •  );
  • }
  • }

33. How Can I Use Javascript In Asp.Net MVC Views?

Ans:

Using Inlivne Javascript code:

  • <script type=”text/javascript”>
  • function AlertName(name)
  • {
  • alert(‘Javascript code called!”);
  • }
  • </script>

Using @RenderSection() directive:

JavaScript files can be bundled up in Bundle.config file and RenderSection can be added in the MVC Views to call add those script files:

  • Budle.config
  • public class BundleConfig
  • {
  • public static void RegisterBundles(BundleCollection bundles)
  • {
  • bundles.Add(new ScriptBundle(“~/bundles/jquery”).Include(
  •  “~/Scripts/jquery-{version}.js”));
  • bundles.Add(new ScriptBundle(“~/bundles/jqueryval”).Include(
  • “~/Scripts/somescript.js”));
  • }
  • }

Call in Razor View:

  • <head>
  • @RenderSection(“scripts”, required: false)
  • </head>

34. How Can I Add Css In Asp.Net MVC Views?

Ans:

Using Inline code:

  • <head>
  • <link href=”@Url.Content(“~/Content/themes/base/Site.css”)”
  • rel=”stylesheet” type=”text/css” />
  • </head>

Using @RenderSection() directive:

CSS files can be bundled up in Bundle.config file and RenderSection can be added in the MVC Views to call add those files:

  • Budle.config
  • public class BundleConfig
  • {
  • public static void RegisterBundles(BundleCollection bundles)
  • {
  • bundles.Add(new       
  • StyleBundle(“~/Content”).Include(
  •  “~/Content/themes/base/jquery.ui.core.css”,
  • }
  • }

Call in Razor View:

  • <head>
  •  @Scripts.Render(“~/bundles/Content”)
  • </head>

35. What Is HelperPage.IsAjax?

Ans:

HelperPage.IsAjax Gets a value that indicates whether Ajax is being used during the request of the web page.

Namspace:

  • System.Web.WebPages  
  • public static bool IsAjax { get; }

It returns true if Ajax is used during the request and false if it isn’t.

36. What Are Non Action methods in Asp.Net MVC And What Is The Use?

Ans:

All public methods are by default treated as Actions in MVC Framework . If you do not want to use it as an action method, decorate it with “NonAction” attribute :

[NonAction]

  • public void TestMethod()
  • {
  • // some logic
  • }

Uses:

There can be many scenarios:

  • If you implement some interface and do not want to call that public method.
  • Use [NonAction] attribute to restrict someones call to your action directly instead of having to go through the ‘asd’ function.
  • Make an action non-accessible from the navigation bar.
  • Avoid exposing an API endpoint during development

37. What Are Actionresult In Asp.Net MVC And What Are The Types?

Ans:

ActionResults are a key component to ASP.NET MVC.

Every method in a controller class returns an ActionResult by default.

Action methods are used to return models to views, file streams, redirect to other controllers etc vis controller.

38. Can We Change Action Name In Asp.Net MVC?

Ans:

There will be scenarios when you will need to change your action name. for example, Say you have an action method GetStudents() which returns a list of students enrolled in a program. You might not want to expose the actual action method to your clients.

You can use a different name in request URL which will map to GetStudents() method at runtime.

You can change the action name using the following syntax:

Public class StudentsController : Controller

  • [ActionName(“StudentsList”)]
  • {
  • public ActionResult GetStudents()
  • {
  • return View();
  • }
  • }

You can call GetStudent() action method using similar sytax:

http://{hostname}/Students/StudentsList

39. Explain ViewStart In Asp.Net MVC

Ans:

The Asp.Net MVC Razor view engine will look for a file with the name ViewStart.cshtml and execute any code residing inside this file first, before executing the code inside an individual view file.

A common usage is to write code to point towards a Layout view which is used as a template across several views. Instead of adding code to declare the Layout page in every view, we can instead, use the _ViewStart page.

  •  @{ 
  • Layout = “~/Views/Shared/__LayoutMain.cshtml”;
  • }
Course Curriculum

Learn ASP Dot Net Training with Industry Standard Concepts By MNC Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

40. What Is RenderBody In Asp.Net MVC?

Ans:

RenderBody is called to render the content of a child view.

The RenderBody method resides in the master / Layout page.

Only one RenderBody method can be used per Layout page.

RenderBody is like the ContentPlaceHolder.

  • <html>
  • <head> 
  • </head>
  • <body>
  • <div id=”main”>
  • @RenderBody()
  • </div>   
  • </body>
  • </html>

41. What Is RenderPage In Asp.Net MVC?

Ans:

RendersPage renders the specified view using a path and file name. In other words, It refers to a page on disk rather than an action method.

The RenderBody method also resides in the master / Layout page.

You can also supply a model you like which could be achieved using a parameter.

  • <html>
  • <head> 
  •  </head>
  • <body>
  • <div id=”main”>
  • <h3>Breakfast:</h3>
  • RenderPage(“BreakfastMenue.cshtml”)
  •  // using Model
  • <h3>Lunch:</h3>
  • RenderPage(“TodaysLunchMenue.cshtml”, LunchMenu)
  • </div>   
  • </body>
  • </html>

42. How Can We Return JSON from action method In ASP.Net MVC?

Ans:

  • public ActionResult GetProperties() {
  • return JSON(new { prop1 = “Test1”, prop2 = “Test2” });
  • }

43. What Is The Simplest Way To Return String From An Action In ASP.Net MVC?

Ans:

  • public ActionResult ReturnString() {
  • return Content(“Simple method returns string!!”);
  • }

44. What Is JQuery?

Ans:

JQuery is a JavaScript library. JQuery

  • has a cross-browser support
  • can be used to work on client-side.
  • is lightweight (write less, do more).
  • is fast
  • is small
  • is feature-rich
  • is Easy to learn
  • is Unobtrusive
  • has excellent API Documentation

You can use JQuery in your applications by downloading the latest version as a single .js file from the official web site.

Most companies like Google, Microsoft and IBM use jQuery.

JQueary makes it easy and simple to navigate to any element in HTML Document and manipulate it.

A quick look at what is available in jQuery:

  • Cross-browser support and detection.
  • AJAX functions
  • CSS functions
  • DOM Selection
  • DOM manipulation
  • DOM transversal
  • Special Effects
  • Attribute manipulation
  • Event detection and handling.
  • JavaScript animation
  • Utilities
  • Custom plugins

45. How To Include jQuery In ASP.Net MVC?

Ans:

You can download and include the link to the script file directly in your page/master page using:

  • <script type=”text/javascript” src=”/scripts/jquery.min.js”></script> 

Or, you can use a Content Delivery network like Google or Microsoft:

  • <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script> 

Or, you can use NuGet Package Manager to install JQuery:

PM> Install-Package jQuery -Version 3.3.1

46. What Is jQuery Unobtrusive Validation In Asp.Net MVC?

Ans:

It is Javascript validation that doesn’t pollute your source code with its own validation code.

We don’t need to call the validate() method as susual. Instead, we can specify requirements using data attributes in HTML.

  • <input type=”text” name=”email” data-val=”true”> 
  • <div class=”validation” data-valmsg-summary=”true”>
  • <ul><li style=”display:none”></li></ul>
  • </div>

47. How Can We Get All Selected checkboxes VALUES In jQuery?

Ans:

You want the :checkbox:checked selector and map to create an array of the values:

  • var checkedValues = $(‘input:checkbox:checked’).map(function() { return this.value; }).get();

48. Can We Run Different Versions Of jQuery On The Same Page?

Ans:

Sure, we can.

This is done by running different versions of jQuery in no-conflict mode.

  • <script src=”jQuery1.3.js”></script>
  • <script>
  • jq13 = jQuery.noConflict(true);
  • </script>
  • <!– original author’s jquery version –>
  • <script src=”jQuery1.2.3.js”></script>

49. How Can We Set Radio Button Selected Value Using Jquery In Asp.Net MVC?

Ans:

  • function RadionButtonSelectedValueSet(name, SelectdValue) {
  • $(‘input[name=”‘ + name+ ‘”][value=”‘ + SelectdValue +   ‘”]’).prop(‘checked’, true);
  • }
  • <script type=”text/javascript”>
  • jQuery(function(){
  • RadionButtonSelectedValueSet(‘RBLExperienceApplicable’, ‘1’);
  • })
  • </script>

50. How Can We RedirectToAction with parameter In ASP.NET MVC?

Ans:

  • return RedirectToAction( “Main”, new RouteValueDictionary( 
  • new { controller = controllerName, action = “Main”, Id = Id } ) );

51. What Is REST (Representational State Transfer)?

Ans:

REST is an architectural style or design pattern, for APIs, defined by Roy Fielding, a computer scientist. REST uses HTTP protocol methods like GET, POST, PUT, and DELETE to work with data.

ASP.Net MVC works in a similar style and provides full support for REST development.

52. What Is Test Driven Development (TDD)?

Ans:

Test Driven Development is a development methodology in which we write tests first before we write the code.

Like any other development model, TDD, tests control your design and development cycles.

53. How Do We Carry Out Testing In Asp.Net MVC?

Ans:

We can carry out unit testing using following frameworks for Asp.Net MVC applications:

    1. 1.xUnit.NET
    2. 2.NUnit
    3. 3.MSTest
    4. 4.MbUnit
    5. 5.TestDriven.NET

54. What Are Data Annotations In Asp.Net MVC?

Ans:

Validation is crucial for the smooth functioning of a web application.

It is not an easy task to implement.

Both Server side and client side techniques are used to make sure the data input correct.

Asp.Net MVC provides classes we can use to validate models using Data annotations attributes which are found in “System.ComponentModel.DataAnnotations” namespace.

These attributes provide server-side validation but client-side validation is also supported.

Here is an example for Data Annotation attributes:

  • Required: A Property is a required field
  • StringLength: Maximum length for a string field
  • Range: Maximum and minimum value for a numeric field
  • DisplayName: The text to display on form fields and validation messages

namespace School.Models

  • public int Price       { get; set; }
  • [DisplayName(“Course Name”)]
  • [StringLength(1024)]
  • public string CourseName { get; set; }        

55. How Can We Use Code Blocks In Views In Asp.Net MVC?

Ans:

Using code blocks in Razor Views is simple. We need to encapsulate our code in in following @{ }

  • For single statement: @{ var message = “Your Message”; }
  • For multi statement:
  • @{
  • var day = DateTime.Now.DayOfWeek;
  • var message = “Hello, Happy ” + day  + “!”;
  • }

55. Describe The Folder Structure For Asp.Net MVC Application.

Ans:

App_Data: Can be used to store some application’s data files like .mdf database files and XML files etc

  • App_Start: Contains core configuration files / classes, applicable for entire application like RouteConfig, BundleConfig, etc.
  • Content: Contains static files, such as CSS files and images etc
  • Controllers: Contains application controllers.
  • Scripts: Contains JavaScript files.
  • Views: The folder contains a folder with a similar name for every controller and a shared folder for views used by more than one views/controllers.

56. Explain HttpGet and HttpPost

Ans:

HttpGet and HttpPost are used to differentiate between betwwen request types for similar functionality.

Consider you want to implement Login functionality:

  • public ActionResult Login() {
  • return View();
  • }
  • public ActionResult Login(string userName, string password) {
  • return View();
  • }

How will you tell MVC to call appropriate method at each stage of the login process?

First, you can present a user with a login page with a GET request.

When user a enters the information you can use a POST request. This way, HttpGet and HttpPost restrict the action according to the type of request.

[HttpGet]

  • public ActionResult Login() {
  • }

[HttpPost]

  • public ActionResult Login(string userName, string password) {
  • return View();
  • }

57. What Is ORM(Object Relational Mapping) In Asp.NET?

Ans:

An Object Relation Mapping(ORM) mechanism helps developers to address, access and manipulate data in applications by programming against a conceptual model instead of programming against a data source.

Benifits:

  • RDBMS independent data access layer
  • Rapid application development
  • Code reduction
  • Use of boilerplate methods for CRUD operations
  • Abstract access to data

Frameworks:

  • Microsoft Entity Framework
  • NHibernate
  • Microsoft LINQ to SQL
  • ORMapster
Course Curriculum

Best ASP.NET Training Course & Get Noticed By Top Hiring Companies

Weekday / Weekend BatchesSee Batch Details

58. How To Configure A Custom Error Page In asp.Net MVC?

Ans:

The HandleErrorAttribute allows you to use a custom page for the error.

Step 1. Update web.config file to allow your application to handle custom errors.

  • <system.web>  
  • <customErrors mode=”On”>  
  • </system.web>  

Step 2. Mark your action method with the atttribute.

[HandleError]  

  • public class HomeController: Controller  
  • {  

  [HandleError]  

  • publicActionResultThrowException()  
  • {  
  • throw new ApplicationException();  
  • }  

Step 3. Add HandleErrorAttribute on the action method.

[HandleError]  

  • public class HomeController: Controller   
  • {  

 [HandleError(View = “CustomErrorView”)]  

  • publicActionResultThrowException()   
  • {  
  • throw new ApplicationException();  
  • }  

59. What Is Validation Summary In Asp.Net MVC?

Ans:

The ValidationSummary is a helper method that could be used to generate an unordered list of validation messages.

Validation messages are stored in the ModelStateDictionary object. You can add custom error methods as well:

  • if (ModelState.IsValid) {     
  • if(exists)
  • {
  • ModelState.AddModelError(string.Empty, “Name already exists.”);
  • return View(std);
  • }
  • }

To display Errors in View:

  • @Html.ValidationSummary(false, “”, new { @class = “text-danger” })

60. What Is Bundling In Asp.Net MVC?

Ans:

Bundling lets you combine more than one JavaScript (.js) files or more than one CSS (.css) files into one unit.

making it a single file reduces number of round requests to server, needed to download the resources, improving page load speed.

61. What Is Minification In Asp.Net MVC?

Ans:

Minification squeezes out whitespace and performs compression to make the file small in size as much as possible without affecting

62. What is SessionId in ASP.Net?

Ans:

When a user is using an application, we need to keep track of them to provide the best service.

We can store a piece of information about the user on our server.

SessionId is a cookie which is used to for that purpose.

The session being an area on the server which can be used to store data in between HTTP requests.

Session[“clientId”] = model.clientId; var clientId = Session[“clientId”];

63. What is ASPXAUTH in ASP.Net

Ans:

There is an authentication mechanism in Asp.Net.

An example for authentication can include;

correct login details

right to a resource

rights to information

right to read/write/modify

If the user is authorized, we can utilize [Authorize] attribute to confirm with the ASPXAUTH cookie.

FormsAuthentication.SetAuthCookie(clientId, false);

1. Define what is ASP.Net?

ASP.NET was developed in direct response to the problems that developers had with classic ASP. Since ASP is in such wide use, Define, However, Microsoft ensured that ASP scripts execute without modification on a machine with the .NET Framework (the ASP engine, ASP.DLL, is not modified when installing the .NET Framework). Thus, IIS can house both ASP and ASP.NET scripts on the same machine.

Advantages of ASP.NET :

  • Separation of Code from HTML:

To make a clean sweep, with ASP.NET you have the ability to completely separate layout and business logic. This makes it much easier for teams of programmers and designers to collaborate efficiently.

  • Support for compiled languages:

The developer can use VB.NET and access features such as strong typing and object-oriented programming. Using compiled languages also means that ASP.NET pages do not suffer the performance penalties associated with interpreted code. ASP.NET pages are precompiled to byte-code and Just In Time (JIT) compiled when first requested. Subsequent requests are directed to the fully compiled code, which is cached until the source changes.

  • Use services provided by the .NET Framework:

The .NET Framework provides class libraries that can be used by your application. Some of the key classes help you with input/output, access to operating system services, data access, or even debugging. We will go into more detail on some of them in this module.

  • Graphical Development Environment:

Visual Studio .NET provides a very rich development environment for web developers. You can drag and drop controls and set properties the way you do in Visual Basic 6. And you have full IntelliSense support, not only for your code but also for HTML and XML.

  • State management:

To refer to the problems mentioned before, ASP.NET provides solutions for session and application state management. The state information can, for example, be kept in memory or stored in a database. It can be shared across web farms, and state information can be recovered, even if the server fails or the connection breaks down.

  • Update files while the server is running:

Components of your application can be updated while the server is online and clients are connected. The framework will use the new files as soon as they are copied to the application. Removed or old files that are still in use are kept in memory until the clients have finished.

  • XML-Based Configuration Files:

Configuration settings in ASP.NET are stored in XML files that you can easily read and edit. You can also easily copy these to another server, along with the other files that comprise your application.

  • *ASP.NET Overview:-

Here are some points that give a quick overview of ASP.NET.

    1. 1.ASP.NET provides services to allow the creation, deployment, and execution of. Web Applications and Web Services.
    2. 2.Like ASP, ASP.NET is a server-side technology.
    3. 3.Web Applications are built using Web Forms. ASP.NET comes with built-in Web Forms controls, which are responsible for generating the user interface. They mirror typical HTML widgets like text boxes or buttons. If these controls do not fit your needs, you are free to create your own user controls.
    4. 4.Web Forms are designed to make building web-based applications as easy as building Visual Basic applications.

64. Define what’s the use of Response.Output.Write()?

Ans:

We can write formatted output using Response.Output.Write().

65. In which event of page cycle is the ViewState available?

Ans:

After the Init() and before the Page_Load().

66. Define what is the difference between Server. Transfer and Response. Redirect?

Ans:

In Server. Transfer page processing transfers from one page to the other page without making a round-trip back to the client’s browser. This provides a faster response with a little less overhead on the server. The clients URL history list or current URL Server does not update in case of Server. Transfer.

Response. Redirect is used to redirect the user’s browser to another page or site. It performs a trip back to the client where the client’s browser is redirected to the new page. The user’s browser history list is updated to reflect the new address.

67. From which base class all Web Forms are inherited?

Ans:

Page class.

68. What are the different validators in ASP.NET?

Ans:

  • Required Field Validator
  • Range Validator
  • Compare Validator
  • Custom Validator
  • Regular expression Validator
  • Summary Validator

69. Which validator control you use if you need to make sure the values in two different controls matched?

Ans:

Compare Validator control.

70. Define what is ViewState?

Ans:

ViewState is used to retain the state of server-side objects between page postbacks.

71. Where the ViewState is stored after the page postback?

Ans:

ViewState is stored in a hidden field on the page at the client side. ViewState is transported to the client and back to the server and is not stored on the server or any other external source.

72. How long the items in ViewState exists?

Ans:

They exist for the life of the current page.

73. Define what are the different Session state management options available in ASP.NET?

Ans:

  • In-Process
  • Out-of-Process.
    In-Process stores the session in memory on the web server.

Out-of-Process Session state management stores data in an external server. The external server may be either a SQL Server or a State Server. All objects stored in session are required to be serializable for Out-of-Process state management.

74. Describe the advantages of writing a managed code application instead of unmanaged one. Define what’s involved in a certain piece of code being managed?

Ans:

“Advantage includes automatic garbage collection,memory management,security,type checking,versioning

Managed code is compiled for the .NET run-time environment. It runs in the Common Language Runtime (CLR), which is the heart of the .NET Framework. The CLR provides services such as security,

memory management, and cross-language integration. Managed applications written to take advantage of the features of the CLR perform more efficiently and safely and take better advantage of developers existing expertise in languages that support the .NET Framework.

Unmanaged code includes all code written before the .NET Framework was introduced—this includes code written to use COM, native Win32, and Visual Basic 6. Because it does not run inside the .NET environment, unmanaged code cannot make use of any .NET managed facilities.”

75. What are Boxing and UnBoxing?

Ans:

Boxing is an implicit conversion of ValueTypes to Reference Types (Object). UnBoxing is an explicit conversion of Reference Types (Object) to its equivalent ValueTypes. It requires type-casting.

76. What is the sequence of operation takes place when a page is loaded?

Ans:

BeginTranaction – only if the request is transacted

Init – every time a page is processed

LoadViewState – Only on postback

ProcessPostData1 – Only on postback

Load – every time

ProcessData2 – Only on Postback

RaiseChangedEvent – Only on Postback

RaisePostBackEvent – Only on Postback

PreRender – everytime

BuildTraceTree – only if tracing is enabled

SaveViewState – every time

Render – Everytime

End Transaction – only if the request is transacted

Trace.EndRequest – only when tracing is enabled

UnloadRecursive – Every request

77. What are the different types of assemblies available and their purpose?

Ans:

Private, Public/shared and Satellite Assemblies.

  • Private Assemblies: Assembly used within an application is known as private assemblies.
  • Public/shared Assemblies: Assembly which can be shared across the application is known as shared assemblies. Strong Name has to be created to create a shared assembly. This can be done using SN.EXE. The same has to be registered using GACUtil.exe (Global Assembly Cache).
  • Satellite Assemblies: These assemblies contain resource files pertaining to a locale (Culture+Language). These assemblies are used in deploying a Global application for different languages.

78. What are the Navigations technique in ASP.NET?

Ans:

Navigation can cause data loss if it not properly handled. We do have many techniques to transfer data from one page to another but every technique has its own importance and benefits.

We will discuss the following techniques in this article.

  • Response.Redirect
  • Server.Transfer
  • Server.Execute
  • Cross page posting

79. Describe the role of inetinfo.exe, aspnet_isapi.dll and aspnet_wp.exe in the page loading process?

Ans:

inetinfo.exe is the Microsoft IIS server running, handling ASP.NET requests among other things. When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request to the actual worker process aspnet_wp.exe.

80. Where do you store the information about the user’s locale?

Ans:

System.Web.UI.Page.Culture

81. Describe the difference between inline and code behind.

Ans:

Inline code is written along side the HTML in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

82. Define what is different b/w webconfig.xml & Machineconfig.xml

Ans:

Web.config & machine.config both are configuration files.Web.config contains settings specific to an application where as machine.config contains settings to a computer. The Configuration system first searches settings in machine.config file & then looks in application configuration files.Web.config, can appear in multiple directories on an ASP.NET Web application server. Each Web.config file applies configuration settings to its own directory and all child directories below it. There is only Machine.config file on a web server.

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

Use the state server or store the state in the database. This can be easily done through a simple setting change in the web.config.

You can specify mode as “state server” or “SQL server”.

Where would you use an iHTTPModule, and Define what are the limitations of any approach you might take in implementing one

“One of ASP.NET’s most useful features is the extensibility of the HTTP pipeline, the path that data takes between client and server. You can use them to extend your ASP.NET applications by adding pre- and post-processing to each HTTP request coming into your application. For example, if you wanted custom authentication facilities for your application, the best technique would be to intercept the request when it comes in and process the request in a custom HTTP module.

83. How is the DLL Hell problem solved in .NET?

Ans:

Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32) but also the version of the assembly.

84. Define what are the ways to deploy an assembly?

Ans:

An MSI installer, a CAB archive, and XCOPY command.

Asp Net Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

85. What is a satellite assembly?

Ans:

When you write a multilingual or multi-cultural application in .NET and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

86. What namespaces are necessary to create a localized application?

Ans:

System.Globalization and System.Resources.

87. What is the smallest unit of execution in .NET?

Ans:

an Assembly.

88. When should you call the garbage collector in .NET?

Ans:

As a good rule, you should not call the garbage collector. Define, However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. Define, However, this is usually not a good practice.

89. How do you convert a value-type to a reference-type?

Ans:

Use Boxing.

90. Define what happens in memory when you Box and Unbox a value-type?

Ans:

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack

91. Describe the difference between a Thread and a Process?

Ans:

A Process is an instance of a running application. And a thread is the Execution stream of the Process. A process can have multiple Thread.

When a process starts a specific memory area is allocated to it. When there are multiple threads in a process, each thread gets a memory for storing the variables in it and plus they can access the global variables which are common for all the thread. Eg. A Microsoft Word is an Application. When you open a word file, an instance of the Word starts and a process is allocated to this instance which has one thread.

92. What is the difference between an EXE and a DLL?

Ans:

  • You can create an object of Dell but not of the EXE.
  • Dell is an In-Process Component whereas EXE is an OUt-Process Component.Exe is for single use whereas you can use Dell for multiple uses.
  • Exe can be started as standalone where all cannot be.

93. Can we add code files of different languages in the App_Code folder?

Ans:

No. The code files must be in the same language to be kept in the App_code folder.

94. What is the GAC? Define what problem does it solve?

Ans:

Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies that are to be shared by several applications on the computer. This area is typically the folder under windows or winnt in the machine.

All the assemblies that need to be shared across applications need to be done through the Global assembly Cache only. Define However it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.

There are several ways to deploy an assembly into the global assembly cache:

  • Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache.
  • Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK.
  • Use Windows Explorer to drag assemblies into the cache.
    GAC solves the problem of DLL Hell and DLL versioning. Unlike earlier situations, GAC can hold two assemblies of the same name but a different version. This ensures that the applications which access a particular assembly continue to access the same assembly even if another version of that assembly is installed on that machine.

95. Define what is an Assembly Qualified Name? Is it a filename? Define How is it different?

Ans:

An assembly qualified name isn’t the filename of the assembly; it’s the internal name of the assembly combined with the assembly version, culture, and public key, thus making it unique.

  • e.g. (“”System.Xml.XmlDocument, System.Xml, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″”)

96. Which protocol is used to call a Web service?

Ans:

HTTP Protocol

97. Can we have multiple web config files for an asp.net application?

Ans:

Yes.

98. Define How information about the user’s locale can be accessed?

Ans:

The information regarding a user’s locale can be accessed by using the System.Web.UI.Page.Culture property.

99. Define what is the base class of .net?

Ans:

System.object

100. Define what is RedirectPermanent in ASP.Net?

Ans:

RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.

101. Define what is MVC?

Ans:

MVC is a framework used to create web applications. The web application base builds on Model-View-Controller pattern which separates the application logic from UI, and the input and events from the user will be controlled by the Controller.

102. Define the working of passport authentication.

Ans:

First of all, it checks the passport authentication cookie. If the cookie is not available then the application redirects the user to Passport Sign on the page. Passport service authenticates the user details on sign on page and if valid then stores the authenticated cookie on the client machine and then redirect the user to the requested page

103. Is the lack of deterministic destruction in .NET a problem?

Ans:

It’s certainly an issue that affects component design. If you have objects that maintain expensive or scarce resources (e.g. database locks), you need to provide some way for the client to tell the object to release the resource when it is done. Microsoft recommends that you provide a method called Dispose() for this purpose. Define, However, this causes problems for distributed objects – in a distributed system who calls the Dispose() method? Some form of reference-counting or ownership-management mechanism is needed to handle distributed objects – unfortunately, the runtime offers no help with this.

104. In which event are the controls fully loaded?

Ans:

Page load event.

105. Define what is delay signing?

Ans:

Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

106. Define what’s the difference between Response.Write() and Response.Output.Write()?

Ans:

Response.Write() and Response.Output.Write() both are used for print output on the screen.

But there are is a difference between both of them

1. Response.Output.Write() is allows us to print formatted output but Response.Write() can’t allow the formatted output.

Example:

  • Response.Output.Write(“.Net{0},”ASP”); // Its write
  • Response.Write(“.Net{0},”ASP”); // Its Wrong

2. As Per Asp.Net 3.5, Response.Write() Has 4 overloads, with Response.Output.Write()

has 17 overloads .

107. When during the page processing cycle is ViewState available?

Ans:

After the Init() and before the Page_Load(), or OnLoad() for a control.

108. Define what’s a bubbled event?

Ans:

When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their event handlers, allowing the main DataGrid event handler to take care of its constituents.

109. Define what data types do the RangeValidator control support?

Ans:

Integer, String, and Date.

110. Explain the differences between Server-side and Client-side code?

Ans:

The server-side code executes on the server. The client-side code executes in the client’s browser.

111. Define what type of code (server or client) is found in a Code-Behind class?

Ans:

The answer is server-side code since code-behind is executed on the server. Define, However, during the code-behind’s execution on the server, it can render client-side code such as JavaScript to be processed in the client’s browser. But just to be clear, code-behind executes on the server, thus making it server-side code.

112. Should user input data validation occur server-side or client-side? Why?

Ans:

All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasible to provide a richer, more responsive experience for the user.

113. Which data type does the RangeValidator control support?

Ans:

The data types supported by the RangeValidator control are Integer, Double, String, Currency, and Date.

114. Define what is the difference between an HtmlInputCheckBox control and an HtmlInputRadioButton control?

Ans:

In HtmlInputCheckBoxcontrol, multiple item selection is possible whereas, in HtmlInputRadioButton controls, we can select an only single item from the group of items.

115. Which namespaces are necessary to create a localized application?

Ans:

System.Globalization

System.Resources

116. Define what are the different types of cookies in ASP.NET?

Ans:

Session Cookie – Resides on the client machine for a single session until the user does not log out.

Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.

117. Define what is the file extension of web service?

Ans:

Web services have file extension .asmx.

118. Define what are the components of ADO.NET?

Ans:

The components of ADO.Net are Dataset, Data Reader, Data Adaptor, Command, connection.

119. Define what is the difference between ExecuteScalar and ExecuteNonQuery?

Ans:

ExecuteScalar returns output value where as ExecuteNonQuery does not return any value but the number of rows affected by the query. ExecuteScalar used for fetching a single value and ExecuteNonQuery used to execute Insert and Update statements.

120. Define what is Remoting?

Ans:

Remoting is a means by which one operating system process, or program, can communicate with another process. The two processes can exist on the same computer or on two computers connected by a LAN or the Internet.

121. Define what’s the use of “GLOBAL.ASAX” file?

Ans:

It allows to executing ASP.NET application level events and setting application-level variables.

122. Define what is a SESSION and APPLICATION object?

Ans:

Session object store information between HTTP requests for a particular user.

Session variables are used to store user-specific information whereas in application variables we can’t store user-specific information.

while the application object is global across users

Are you looking training with Right Jobs?

Contact Us

Popular Courses