ASP.NET Exclusive Interview Questions and Answers (348) - Page 18

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

348 records found.

Get 650+ Questpond's Interview videos on discount

.NET/ASP.NET Interview Question - What is WebService and how different its from Remoting?

WebServices is a cross platform where we can invoke object which are lying on different server or different georphical
location.

Both WebService and Remoting are used for same Purpose but the difference in Remoting is that both the server and client should be .NET platform while in WebService the server and client can be in different platform.

Remoting is faster than WebService.

WebService can be access only through http protocol but Remoting can access by any kind of protocol like TCP,HTTP,SMPT,FTP.

Regards,



.NET/ASP.NET Interview Question - What is WSDL?

WSDL(Web Services Description Language) is an XML-based language which describes the Web services,Method name,Function name and Input Output parameter.


To see how WSDL look like, just go to Visual Studio create a webservice and run .asmx file you will see the output like below diagram and when you click on service description then the WSDL will be seen.



 

 <?xml version="1.0" encoding="utf-8" ?> 
- <wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="HelloWorld">
  <s:complexType />  
</s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />

  </s:sequence>
  </s:complexType> 
</s:element>
  </s:schema> 
</wsdl:types>
+ <wsdl:message name="HelloWorldSoapIn"> 
<wsdl:part name="parameters" element="tns:HelloWorld" />  
</wsdl:message>
- <wsdl:message
name="HelloWorldSoapOut">
  <wsdl:part name="parameters"
element="tns:HelloWorldResponse" />
  </wsdl:message>
<wsdl:portType name="WebService1Soap">
- <wsdl:operation
name="HelloWorld">
  <wsdl:input message="tns:HelloWorldSoapIn"/>
  <wsdl:output message="tns:HelloWorldSoapOut" />

  </wsdl:operation>
  </wsdl:portType>


Regards,




.NET/ASP.NET interview Questions - What is Render and PreRender?

PreRender: -PreRender is an event which is used for modifying server controls just  before sending them to the client.

Render: -Render is an method which actually puts the HTML output to the response stream.

Lets see an simple example to get an better idea, below is the code snippet for the same.

To use PreRender event, we have to override it and can make neccessary changes to the controls we want to.
protected override void OnPreRender(EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
row.ForeColor = Color.Blue;
}
}
In the above code snippet, I have override the PreRender event and just changed the forecolor of the GridView.

Now lets see how we can code for Render. Below is the code snippet for the same, in which I have override the Render and using “HtmlTextWriter” just displayed a simple HTML text output.
protected override void Render(HtmlTextWriter writer)
{
writer.Write("This displays the grid in blue color");
base.Render(writer);
}
Below is the full code snippet so that you can try it by yourself and see the respective result.
using System.Drawing;
using System.Collections;

namespace Data
{
public class Customer
{
public string CustomerCode { set; get; }
public string CustomerName { set; get; }
}
public partial class WebForm1 : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
LoadGrid();
}
public void LoadGrid()
{
ArrayList objArray = new ArrayList();
Customer ObjCustomer = new Customer();
ObjCustomer.CustomerCode = "1001";
ObjCustomer.CustomerName = "shiv";
objArray.Add(ObjCustomer);
ObjCustomer = new Customer();
ObjCustomer.CustomerCode = "1002";
ObjCustomer.CustomerName = "Feroz";
objArray.Add(ObjCustomer);
GridView1.DataSource = objArray;
GridView1.DataBind();
}
protected override void OnPreRender(EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
row.ForeColor = Color.Blue;
}

}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("This displays the grid in blue color");
base.Render(writer);
}
}
}
In the above code snippet, I have used prerender event to change the forecolor of the girdview before the gridview is displayed on the client browser and I have override the render method to display the html output to the response stream.

PreRender event executed before the render method gets called which creates the HTML code using the HtmlWriter.so in other words prerender event fires first and do the necessary changes to the server control and later the render method is called.

In below diagram you can see that the gridview forecolor is been changed because of the prerender event and the render method display the html output using html writer.
render.png
In the following video, view samples of various questions asked in C# and .NET interview.


.NET ans ASP.NET interview Question - What are different types of assemblies?

In .NET there are basically three different types of assemblies as follows.


1.Private assemblies:-A private assembly is normally used by a single application and is stored in the application's directory.


2.Public/shared assemblies:- A shared assembly is normally stored in the global assembly cache which is a repository of assemblies maintained by the .NET runtime.


3.satellite assemblies:-Satellite assemblies are often used to deploy language-specific resources for an application. These language-specific assemblies work in side-by-side execution because the application has a separate product ID for each language and installs satellite assemblies in a language-specific subdirectory for each language.


You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.



ASP.NET/.NET interview Question - How do you encrypt the connection strings in web.config file?

When you host your site on server, sometimes happens that your site is handled by an third party or any other individual who is responsible to handle the server. As your site is handled or manage by another person it can be possible for that person to view your connection string and can make changes to the same. So in order avoid this we need to encrypt your connection string.

This can be achieved by using aspnet_regiis tool provided by the ASP.NET.

It’s a very simple 3 steps process.

Step 1:- Let first define the connection string in web.config file like below code snippet.

 <connectionStrings>
    <add name="Constr" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName; Integrated Security=True"/>
  </connectionStrings>

In the above snippet code you can see that the connection string easily visible by anyone because it is in decrypted format. Hence to prevent or protect the connection string we need to encrypt connection string in such a way that it is not visible to anyone.

Step 2: - Just go to Visual Studio Command Prompt and use aspnet_regiis tool to encrypt the defined connection string like below diagram.


e1.png

Now just execute the Visual Studio Command Prompt and if the encryption is done successfully a message will be displayed like below diagram.


e2.png

Step 3:- Go to web.config file and you will see that connection string is now in encrypted format like below diagram.


e3.png


You will be also interested in watching the below video, which are also
asked in most of the interviews and favourable question of interviewers.



.NET and ASP.NET interview questions: - How can we consume web services in AJAX?

The simple answer to the above question is by using the ‘asp:ServiceReference’ tag inside ‘asp:scriptmanager’ tag as shown in the below code snippet. Inside the ‘servicereference’ tag provide the ASMX file name.



Following is the video for consuming webservices in AJAX: -


Now let’s go a for a long answer and a step by step answer.


Normally consumption of web services happens as shown in the below figure. The browser Ajax controls calls the ASP.NET code and the ASP.NET code consumes the web service. But there are scenarios where you would like to call the web services directly from the Ajax JavaScript functions rather than calling via the behind code. This article will demonstrate how we can achieve the same.



Step 1: Create your Customer Class


The first step is to create the customer class as shown below. So our customer class has 4 properties on customer id, first name, address and designation.

public class Customers

{
// private properties
private int _intCustomerID;
private string _strFirstName;
private string _strAddress;
private string _strDesignation;

// Public property and
public int CustomerID
{
get
{
return _intCustomerID;
}
set
{
_intCustomerID = value;
}
}

public string FirstName
{
get
{
return _strFirstName;
}
set
{
_strFirstName = value;
}
}

Step 2: Create your Web Service


The next step is we need to create the web service which exposes the customer class to our UI. Below is a simple web service which has encapsulated customer collection. In the constructor, we are loading some dummy data into the list of customers as shown in the below code snippet:

[System.Web.Script.Services.ScriptService]

public class Customer : System.Web.Services.WebService {

// Customer collection
List listcust = new List();
public Customer ()
{
//Load some dummy data in to customer collection.
listcust.Clear();
Customers cust = new Customers();
cust.CustomerID = 1;
cust.FirstName = "Taha";
cust.Address = "Live in India";
cust.Designation = "Software Developer";
listcust.Add(cust);

cust = new Customers();
cust.CustomerID = 2;
cust.FirstName = "Shyam";
cust.Address = "Live in Austrailia";
cust.Designation = "Web Designer";
listcust.Add(cust);

cust = new Customers();
cust.CustomerID = 3;
cust.FirstName = "Khadak";
cust.Address = "Live in London";
cust.Designation = "Architect";
listcust.Add(cust);
}

// This function exposes all customers to the end client’
[WebMethod]
public List LoadCustomers()
{
return listcust;
}

// This function helps us to get customer object based in ID

[WebMethod]
public Customers LoadSingleCustomers(int _customerid)
{
return (Customers)listcust[_customerid-1];
}

We are also exposing two functions through the web service, one which gives out a list of customers and another which gives out individual customer data based on customer id.


Step 3: Reference your Web Service using the asp:servicereference


Using the ‘asp:ServiceReference’, we will then point the path to the ASMX file as shown in the below code snippet. This will generate the JavaScript proxy which can be used to call the customer object.



Step 4: Call the Webservice and the JavaScript Code


Once you have defined the proxy, you can now call the ‘Customer’ proxy directly to make method calls.

function LoadAll() 

{
Customer.LoadCustomers(LoadCustomerToSelectOption, ErrorHandler, TimeOutHandler);
}

When you call the JavaScript proxy object, we need to provide three functions; the first function (‘LoadCustomerToSelectOption’) will be called when the web service finishes and returns data. The data will be returned in the fill variable which will then be looped and added to the customer combo box.

function LoadCustomerToSelectOption(Fill)

{
var select = document.getElementById("cmbCustomers");

for (var i = 0; i < Fill.length; i++)
{
var value = new Option(Fill[i].FirstName, Fill[i].CustomerID);
select.options.add(value);
}
}

There are two more functions which are attached; one which handles error and the other which handles time out. Below are the code snippets for the same:

function ErrorHandler(result) 

{
var msg = result.get_exceptionType() + "\r\n";
msg += result.get_message() + "\r\n";
msg += result.get_stackTrace();
alert(msg);
}
function TimeOutHandler(result)
{
alert("Timeout :" + result);
}

.NET and ASP.NET interview questions: What is MVC, MVP and MVVM pattern?

MVC, MVP and MVVM are design patterns which come under the presentation pattern category and they help to remove any kind of cluttered code in UI like manipulation of user interfaces and maintaining state. Thus keeping your UI code cleaner and better to maintain.


MVC(Model view controller) pattern divides the architecture into 3 parts model, view and controller. The first request comes to the controller and the controller then decides which view to be displayed and ties up the model with the view accordingly.


MVP (Model view presenter) has the same goals as MVC i.e. separating the UI from the model. It does the same by using a presenter class. The UI talks via an interface to the presenter class and the presenter class talks with the model.


MVVM is an architectural pattern with the focus of removing UI cluttered code. It does the same by using an extra class called as view model. MVVM is mostly suitable for Silverlight and WPF projects because of the rich bindings provided by the technologies.


Following you can see step by step video to create simple application using ASP.NET MVC template:



5 Important ASP.NET MVC interview questions

Below are some very important MVC ( Model view controller ) interview questions asked again and again.

What does MVC stand for?

The full form is model view controller.

What exactly is MVC?

Model view controller pattern is a architectural design pattern.

So how does it help?

It helps to create reusable code by seperating the logic in to view, controller and model.
View -- Will have the look and feel
Controller -- will have the code to club the model and view.
Model -- will have the business logic.

How can we do MVC in ASP.NET?

MVC in ASP.NET is done by using the Visual studio MVC template.

How do you create a simple project using the MVC template?

See the below complete video series which will help you to learn MVC step by step.





More ASP.NET Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories