Monday, 20 March 2017

ASP.NET interview questions Part-8

1. Ques: What are the difference between Web services and .Net Remoting ?
Answer:
Web services
  • Web Services are meant to be interoperable, meaning that they can be used across platforms. 
  • Web service create a Web service class derived from the System.Web.Services.WebService class and add the methods (functionality) with the WebMethod attribute. These methods can be invoked by sending HTTP requests using SOAP.
  • Web service create a proxy class for your Web service using either wsdl.exe utility or the Add Web Reference option in VS.NET. The Web service proxy hides all the network and marshaling plumbing from the application code, so using the Web service looks just like using any other local object
  • ASP.NET Web Services may be accessed using HTTP only.
  • Web Service is Stateless
Dot Net Remoting
  • The primary distinction is that .NET Remoting is only useful for .NET to .NET scenarios. 
  • the remote object is implemented in a class derived from System.MarshalByRefObject and MarshalByRefObject class provides the core foundation for enabling remote access of objects across application domains.
  • Remote object is confined to the application domain where it is created. In .NET remoting, a client doesn't call the methods directly; instead a proxy object is used to invoke methods on the remote object. Every public method that we define in the remote object class is available to be called from clients.
  • Remoting objects may be accessed over any protocol like TCP, SMTP, and HTTP. 
  • Remoting has support for both stateless and with-state environment, which is achieved using Singleton and Singlecall activation 

2. Ques:  What is the purpose of HTTP, SOAP in web-service ?
Answer:
HTTP(Hyper Text Transfer Protocol) is the set of slandered for the web requests. SOAP ( Simple Object Access Protocol) is the message format which is used to send and receive data in the specific message format in case of services.
Web Service transmits and receive the data in form of Message and each message should have some format so that it will be understandable by the browser and getting the responses in the same format. SOAP defines the common format of the messages which is XML format and understandably by all the technologies(as XML is platform independent).


3. Ques: What is  absolute expiration and sliding-time expiration ? What is the difference between them ?
Answer:
ASP.NET provides the functionality to create cache. It also provides the option to set the expiration time after which the cache would no longer be available. This is called "Time Based Expiration".
This expiration is of 2 types: 1. Absolute Expiration 2. Sliding ExpirationIn

Absolute Expiration the cache will be expired after a particular time irrespective of the fact whether it has been used or not in that time span. Whereas, in Sliding Time Expiration, the cache will be expired after a particular time only if it has not been used during that time span.The syntax to declare them are as follow:string cacheData = "Let's cache this data";
//Absolute Expiration Cache.Insert("AbsoluteCacheKey", cacheData, null,DateTime.Now.AddMinutes(1), System.Web.Caching.Cache.NoSlidingExpiration);
//Sliding Expiration Cache.Insert("SlidingExpiration", cacheData, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(1));

Ex: I have created the a string to be cache that can be any serialized data. In the absolute expiration you can see that it will expires after one minute whether its accessed or not. While in sliding expiration it will expire cache if cache is not accessed within specified time like one minute.

Absolute expiration
It will expire the entry after a set amount of time.

sliding-time expiration
It will expire the entry if it hasn't been accessed in a set amount of time.


4. Ques:  What are the important Namespaces in Asp.net ?
Answer:
Namespaces in Asp.net  given as
System.Web 
System.web namespace holds some basic ingredients which includes classes and built-in Objects like
  • Server
  • Application
  • Request
  • Response
And Classes used for managing
  • Cookies
  • Configuring page caching
  • Tracing Implementation
  • Retrieving Information of Web Server and client browser
System.Web.services 
The System.Web.services namespace is a initial point for creating the web services. It contains web service classes , which allow to create XML web services using Asp.Net . XML web services provides feature to exchange messages in loosely coupled environment. using protocol like SOAP , HTTP , XML .

Some classes are as
  • WebMethodAttribute
  • Webservice
  • WebServiceAttribute
  • WebServiceBindingAttribute
System.web.UI.WebControls 
he System.web.UI.WebControls namespace contains classes that provides to create web server controls on web pages. These controls run on the server so we can programmaticaly control elements
Some classes are as follows
  • Calendar
  • Check Box
  • Button
  • Base Data Bound Control
System.web.UI 
The System.web.UI namespace includes classes that allows to create server controls with data- binding functionality , which has ability to save view state of given control and pages (.aspx pages) .
Many of these types allows to support for controls System.web.UI .Html controls. It is a base class for all HTML ,Web, and User Controls. Every aspx pages comes under it. Control classes provides common set of functionslity

System.web.sessionstate
Session state management comes under The System.web.sessionstate namespace . That enable storage of data specific to a single client with in a web application on the server. Session state is ideal for sensitive data such as mailing address , credit card number , password , important numbers etc. Sesssion state can be used with clients that do not support cookies.

Some classes are as follows
  • HttpSessionState
  • HttpSessionStateContainer
  • SessionIDManager
  • SessionStateModule etc


5. Ques: What are different types of directives in .NET? Explain each of them .
Answer:
@Page
@Control
@Import
@Implements
@Register
@Assembly
@MasterType
@Output Cache
@PreviousPageType
@Reference
@Master

 @Page Directive
This directive use for page-specific attributes by the ASP.NET page parser and compiler. Can be included only in .aspx files and also define the page language used just like c#,VB etc.

<%@Page Language="C#" AutoEventWIreup="false" CodeFile="Default.aspx.cs" Inherits="_Default"%>

@Control
control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files.
This directive also define the view state of page. <%@ Control Language="VB" EnableViewState="false" %>

@Import
It is Explicitly imports a namespace into a page or user control. The Import directive cannot have more than one namespace attribute. To import multiple namespaces, use multiple @Import directives.Its helps in importing of files. <% @ Import Namespace="System.web" %>

@Register 
when we create a user control and you drag that user control onto your page then you will see the @Register directive. This directive registers your user control on the page so that the control can be accessed by the page.
<%@ Register TagPrefix="MayTag Namespace="MyName.MyNameSpace" Assembly="MyAssembly"%>

@Assembly 
The @Assembly Directive attaches assemblies to the page or an ASP.NET user control thereby all the assembly classes and interfaces are available to the class. 
 <%@ Assembly Name="MyAssembly" %>
 <%@ Assembly Src="MySource.vb" %>

@Previouspagetype
This directive specifies the page from which any cross-page posting originates.

@Implements
The @Implements Directive gets the ASP.NET pages to implement .Net framework interfaces. This directive only supports a single attribute interface.
<%@Implements Interface="System.Web.UI.IValidator"%>

@MasterType 
The @MasterType Directive connects a class name to the ASP.NET page for getting strongly typed references or members contained in the specified Master Page. This directive supports the two attributes Typename and virtualpath. Typename sets the name of the derived class from which to get the strongly typed or reference members and virtualpath sets the location of the page from which these are retrieved.
<%@MasterType VirtualPath="/MasterPage1.master"%>

@output cache
It controls the output caching policies of an ASP.NET page.
<%@ OutputCache Duration ="180" VaryByParam="None"%>

No comments:

Post a Comment

Thank you for comment