FAQ Microsoft Technology


There are 6 objects in ASP.net
a) Server
b) Session
c) Application
d) ObjectContext
e) Response
f) Request
How can you deploy an asp.net application ?
You can deploy an ASP.NET Web application using any one of the following three deploymentoptions.
a)Deployment using VS.NET installer
b)Using the Copy Project option in VS .NET
c) XCOPY Deployment
User control
1) Reusability web page
2) We can?t add to toolbox
3) Just drag and drop from solution explorer to page (aspx)
4) Good for static layout
5) Easier to create
6) Not complied into DLL
7) A single copy of the control is required in each application

Custom controls
1) Reusability of control (or extend functionalities of existing control)
2) We can add toolbox
3) Just drag and drop from toolbox
4) You can register user control to. Aspx page by Register tag
5) Good for dynamic layout
6) Hard to create
7) Compiled in to dll
Name atleast three methods of response object other than Redirect.
Answer1
a) Response.Clear( )
Clears the content of the current output stream.
b) Response.Close( )
Closes the network socket for the current response.
c) Response.End( )
Stops processing the current request and sends all buffered content to the client immediately.
How many types of cookies are there in ASP.NET ?
they are 2 types of cookies.
1)Session Cookies & 2) Peristance Cookies

1. Single valued
request.cookies(”dotnetfunda”)=”Sheo”
2. Multi valued
request.cookies(”donetfunda”)(”uname”)=”MAJITH?
Persistent cookies are stored on your computer hard disk. They stay on your hard disk and can be accessed by web servers until they are deleted or have expired. Persistent cookies are not affected by your browser setting that deletes temporary files when you close your browser.
Non-persistent cookies are saved only while your web browser is running. They can be used by a web server only until you close your browser. They are not saved on your disk. Microsoft Internet Explorer 5.5 can be configured to accept non-persistent cookies but reject persistent cookies.
Agile methodology :-
Agile is software development methodology.
 It is very effective where Client frequently changes his requirement.
Since it has more iteration so you can assure a solution that meets clients requirement. More than one build deployement for a project.
It involves more client interection and testing effort.
There are two methods by which this methodology can be implemented:-
1- Scrum
2- Extreme Progamming
Scrum: Each iteration would called a scrum which can be a 1- 2 Months.In Scrum Client prioritise his requirements what he want first. If developer did not meets all the requirement which was being fixed for a perticular scrum than rest of the development part would be transferred to the next scrum (would be delievered in the next build), means developer cann't increase time decided for a scrum. Its fixed.
Extreme Programming (XP): here iteration period would be less then in scrum , which is being 2-4 weeks. Here developer prioritise what to do first on the basis of client requirement.
Agile Methodology- Characteristics
 Ø Frequent Delivery
Ø More Iterations
 Ø Test frequently
 Ø Less defects
Muliple inheritence means deriving a new class from one or more base class.
MULTIPLE INHERIENCE:one depived class from many base class is reffered to MI
Polymorphism :-
Polymorphism is a property in which a single object can have more than 1 form
There are two types of polymorphism
1-Dynamic polymorphism
2-static polymorphism static polymorphism(early binding)
dynamic polymorphism(late binding) :-
 class model should be based on inheritance model.virtual function is used for it.
 that means the linking between function call and object is resolved at run time is known as dynamic polymorphism.

Static polymorphism static polymorphism(early binding) :-
there in only one class is sufficient to call the overloaded function.it is predefine that which function want to be call.
that means the linking between function call and object is resolved at compile time is known as static polymorphism.
Cross-Page Posting : -
ASP.NET by default, submits the form to the same page. Cross page posting is submitting the form to a different page
PostBackUrl’ property of a Button to the URL of the target page, Default2.aspx.
<asp:Button ID="Button1" runat="server" PostBackUrl="~/Default2.aspx" Text="TargetButton" /></div>
if (Page.PreviousPage != null)
{
Button btn = (Button)(Page.PreviousPage.FindControl("button1"));
Label1.Text = btn.Text;
}
Why .net do not support multiple inheritance?
multiple inheritance injects a lot of complexity in implementing casting, layout, dispatch, field access, serialization, identity comparisons, verifiability, reflection, generics, and probably lots of other places.
Is it possible to store view state in server side?
Yes, we can implement server side viewstate.
For this we have to override two virtual methods LoadPageStateFromPersistenceMedium() and SavePageStateToPersistenceMedium() of System.Web.UI.Page (on your aspx page)
Sample code:
//overriding method of Page class
protected override object LoadPageStateFromPersistenceMedium()
{
//If server side enabled use it, otherwise use original base class implementation
if (ConfigurationManager.AppSettings["ServerSideEnabled"].Equals("true"))
{
//Your implementation here.
}
else
{
return base.LoadPageStateFromPersistenceMedium();
}
}
protected override void SavePageStateToPersistenceMedium(object state)
{
//If server side enabled use it, otherwise use original base class implementation
if (ConfigurationManager.AppSettings["ServerSideEnabled"].Equals("true"))
{
//Your implementation here.
}
else
{
base.SavePageStateToPersistenceMedium(state);
}
}
Difference Between Session and Cache : -
The key difference is session is per user, while cache will be for application scoped items.
Items put into a session will stay there, until the session ends. Items in the cache can expire (will be removed from cache) after a specified amount of time
·         The session state can be kept external (state server, SQL server) and shared between several instances of your web app (for load balancing).
·         This is not the case with the cache.
Cookies : -
Cookies are small pieces of information stored in the client computer. They are limited to 4K in size
Cookies are two types:
In-memory cookies also called as Session cookies or Non-Persistent cookies
·         These cookies are saved in memory and will be lost while closing your browser.
·         Persistent cookies
·         A persistent cookie is saved as a text file in the file system of the client computer usually under Temporary Internet Files folder. To create persistent cookie we need to set cookie Expires property. Generally we go for persistent cookies to implement the features like “Remember me” option OR to store user information such as selected theme.
[Code=cs]
HttpCookie cookie = new HttpCookie("Username", "Mr. Ponna");
cookie.Expires = DateTime.Now.AddDays(7); // creating A persistent cookie for 7 days

Response.Cookies.Add(cookie);
Correlated Query : -
A correlated sub-query is a term used for specific types of queries in SQL. It is a sub-query (a query nested inside another query) that uses values from the outer query in its WHERE clause
What is difference between STUFF and REPLACE in SQL Server
REPLACE is used to replace all the repition.
STUFF function is used to overwrite existing characters.

Using this syntax, STUFF (string_expression, start, length, replacement_characters)

for Ex: SELECT STUFF('SQL SERVER is USEFUL',5,6,'DATABASE')

Here SERVER is replaced with DATABASE
5 is position of S(ERVER)
6 is length of (1S 2E 3R 4V 5E 6R)

OUT PUT : SQL DATABASE is USEFUL
What are magic tables in SQL Server
Sometimes we need to know about the data which is being inserted/deleted by triggers in database.

Whenever a trigger fires in response to the INSERT, DELETE, or UPDATE statement, two special tables are created. These are the inserted and the deleted tables. They are also referred to as the magic tables. These are the conceptual tables and are similar in structure to the table on which trigger is defined (the trigger table).

The inserted table contains a copy of all records that are inserted in the trigger table.
The deleted table contains all records that have been deleted from deleted from the trigger table.
Whenever any updation takes place, the trigger uses both the inserted and deleted tables
What is the difference between function and stored procedure ?
1.Procedure can return zero or n values whereas function can return one value which is mandatory.
2.Procedures can have input,output parameters for it whereas functions can have only input parameters.
3.Procedure allow select as well as DML statement in it whereas function allow only select statement in it.
4.Functions can be called from procedure whereas procedures cannot be called from function.
5.Exception can be handled by try-catch block in a procedure whereas try-catch block cannot be used in a function.
6.We can go for transaction management in procedure whereas we can't go in function.
7.Procedures can not be utilized in a select statement whereas function can be embedded in a select statement.
What are different types of cursors available in SQL Server 2005
Following are different types of cursors available in SQL Server 2005
Base table
Static
Forward-only
Forward-only/Read-only
Keyset-driven
Base table: Base table cursors are the lowest level of cursor available. Base table cursors can scroll forward or backward with minimal cost, and can be updated
Static: Cursor can move to any record but the changes on the data can’t be seen.
Dynamic: Most resource extensive. Cursor can move anywhere and all the changes on the data can be viewed.
Forward-only: Cursor moves one step forward, can’t move backwards.
Keyset-driven: Only updated data can be viewed, deleted and inserted data cannot be viewed
What is difference Between GETDATE and SYSDATETIME
When we use GETDATE the precision is till miliseconds and in case of SYSDATETIME the precision is till nanoseconds.
Write a query to get max salary and second max salary in order in one query
SELECT TOP 1 sal FROM(SELECT DISTINCT( Top 2 sal) FROM employees ORDER
BY sal DESC)

What is WCF
WCF = Windows Communication Foundation
A communication-oriented set of APIs and a "runtime" inside .NET to make two (or more) systems talk to one another. It basically replaces ASMX (ASP.NET web services), .NET remoting (object remoting) and a few other communication-related API's and products in the .NET space.
It can and should be used any time two systems (apps, machines) need to exchange information, basically. It's the foundation for all "connected systems".
WCF which bindings supports the reliable session
In WCF, following bindings supports the reliable session
wsHttpBinding
wsDualHttpBinding
wsFederationHttpBinding
netTcpBinding
What is serialization and How many types of serialization are there in NET
Serialization:
Serialization is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location. This storage location can be a physical file, database or ASP.NET Cache.
Serialization is the technology that enables an object to be converted into a linear stream of data that can be easily passed across process boundaries and machines. This stream of data needs to be in a format that can be understood by both ends of a communication channel so that the object can be serialized and reconstructed easily.
Serialization can be of the following types:
Binary Serialization
SOAP Serialization
XML Serialization
Custom Serialization

Why can' t  serialize hashtables
The thing about XML Serialization is that it's not just about creating a stream of bytes. It's also about creating an XML Schema that this stream of bytes would validate against. There's no good way in XML Schema to represent a dictionary.

This limitation is not only Hashtable, the XmlSerializer cannot process classes implementing the IDictionary interface due to the fact that a hashtable does not have a counterpart in the XSD type system. The only solution is to implement a custom hashtable that does not implement the IDictionary interface.
What is difference between out and ref keywords in C# NET
ref parameter is both input and o/p parameter
out parameter is only output parameter
As ref parameter treated as input parameter too, ref requires that the variable be initialized before being passed; otherwise you will receive compiler error.
As out parameter treated only as output parameter, out arguments need not be initialized prior to being passed, the calling method is required to assign a value before the method returns 
Patterns implemented in the ASP.NET Page Framework
Following three patterns govern the ASP.NET Page Framework.
Front Controller Pattern
Page Controller Pattern
Model View Controller Pattern
When ASP.NET determines which HttpHandler to pass a request to, it uses something similar to a Front Controller. Front Controller is characterized by a single handler for all requests (like System.Web.UI.Page). Once the request reaches the Page class, though, the Page Controller pattern takes over.
Within the ASP.NET implementation of Page Controller, there are elements of the Model
View Controller pattern. Model View Controller separates the model (business objects, data, and processes) from the view (the display of information). The controller responds to user input and updates the model and view
Is it possible to have a same control name in aspx page and in its master page
Yes, we can have. There is no such a restriction in asp.net.
How to do a deep copy and shallow copy in NET
Shallow copy is done using .Clone() and Deep copy is done using .Copy() on which ever you call the methods
System.Array.CopyTo() - Deep copies an Array
How to stop or get offline ASP NET web application
There are three common ways to make ASP.NET application offline:
Using IIS to stop website
Use App_Offline.htm file
Use HttpRuntime element in Web.config
Using httpRuntime element in web.config
To make web application offline, you can use Web Site Administration Tool. If you can't use WSAT, edit web.config manually. Add <httpRuntime enable="false" /> inside <system.web> tag, like this:
<configuration>
<system.web>
<httpRuntime enable="false"/>
<system.web>
<configuration>
What are possible reasons why ASP NET application could restart
ASP.NET application could restart because really a lot of reasons. It probably happens more often than you think. ASP.NET web application will restart because of:
Change in Web.Config file. Change of any parameter, adding of space character or even changing file's modified date will cause app restart.
Change in machine.config, just like for web.config.
Change in /bin folder. Application will restart if you add, update or delete any file in /bin folder.
Change in App_Code folder. Adding, deleting or editing classes inside App_Code will cause application restart.
Change in Global.asax file, like in web.config.
Change in App_LocalResources folder
Change in App_GlobalResources folder
Change in App_WebReferences folder
Change in Profile configuration


Reached compilation limit, defined with numRecompilesBeforeAppRestart in machine.config file. Default value is 15. ASP.NET watches for any changes in files. When certain number (15 by default) of files is changed, web application is restarted automatically. The reason for this is to save memory on server. On some websites where files are generated dynamically, this could cause frequent restarts.
Antivirus software changes file's modified date. Antivirus program scans files like Web.config or Global.asax. Some antivirus programs change Modified date of these files and that cause pretty frequent restarts, which decrease website performances.
IIS restarts, and all websites will restart too.
Change of physical path to web application
IIS recycled website due to inactivity (20 minutes by default). If website has no visitors, IIS will unload it from memory to save resources. Application will be started again on when next visitor comes.
Can we set Master page dynamically at runtime
Yes. Set the MasterPageFile property only during the PreInit page event—that is, before the runtime begins working on the request (since the rendering of the page with the master page occurs prior to the Init event)
protected void Page_PreInit(object sender, EventArgs e)
{
MasterPageFile = "simple2.master";
}
If you try to set the MasterPageFile property in Init or Load event handlers, an exception is raised
How to identify which control caused Postback
Below code will help you to identify the control which caused the postback.
The name of the control which caused the postback will be set in
__EVENTTARGET by __doPostBack JavaScript function before the form is
submitted.
string ctrlname = page.Request.Params.Get("__EVENTTARGET");
if (ctrlname != null && ctrlname != string.Empty)
{
return this.Page.FindControl(ctrlname);
}

How can you improve the web application performance when the application is in live production
Improving performance for web application without changing the code has its limit and biggest challenge.

Below are few things that you can perform to improve performance
Check database indexes and tune database either by using Database Engine Tuning Advisor or manually
Check the database health periodically and fine tune it (DBA task)
Enable Caching at IIS, if you have any static content or the content changes less frequenly
Enabling HTTP Compression at IIS, if you application is bandwidth thirsty and consumes more network bandwidth for page loading
Increase the web server scalability either by Scaling up or Scale outing. know more about Scale Up vs. Scale Out
How to make an ASP page to refresh after certain time
Inorder to make a particular page to be refreshed after a particular time at page level of the asp page we need to specify like this :
<meta http-equiv="refresh" content="15" />
The above statement will make a particular page to be refreshed for every 15 seconds.
In real time if we see cricinfo webpage for every default period of time the page gets refreshed
Explain the ASP NET Page Directives
@ Assembly - Links an assembly to the current page or user control declaratively.
@ Control - Defines control-specific attributes used by the ASP.NET page parser and compiler and can be included only in .ascx files (user controls).
@ Implements - Indicates that a page or user control implements a specified .NET Framework interface declaratively.
@ Import - Imports a namespace into a page or user control explicitly.
@ Master - Identifies a page as a master page and defines attributes used by the ASP.NET page parser and compiler and can be included only in .master files.
@ MasterType - Defines the class or virtual path used to type the Master property of a page.
@ OutputCache - Controls the output caching policies of a page or user control declaratively.

@ Page - Defines page-specific attributes used by the ASP.NET page parser and compiler and can be included only in .aspx files.
@ PreviousPageType - Creates a strongly typed reference to the source page from the target of a cross-page posting.
@ Reference - Links a page, user control, or COM control to the current page or user control declaratively.
@ Register - Associates aliases with namespaces and classes, which allow user controls and custom server controls to be rendered when included in a requested page or user control.
How do we access Master Page Controls from Content Pages
Yes. We can access master page controls from the content pages. Below are the examples towards the same.
Example1:TextBox tb = (TextBox)Master.FindControl("txtMaster");
tb.Text = "Something";
Example2:
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if (mpContentPlaceHolder != null)
{
mpTextBox = (TextBox)mpContentPlaceHolder.FindControl("TextBox1");
if (mpTextBox != null)
{
mpTextBox.Text = "TextBox found!";
}
}
How to change website configuration without restarting ASP NET application
Any change in Web.config file will cause ASP.NET application to restart. But, it is possible to create one or more external .config files which don't cause application restart. To connect external .config files with main Web.config, use configSource parameter. Here is an example code snippet, used to read external configuration from three files:
<connectionStrings configSource="db.config"/>
<appSettings configSource="app.config"/>
<system.net>
<mailSettings>
<smtp configSource="mail.config"/>
</mailSettings>
</system.net>

How to update web config programatically
protected void EditConfigButton_Click(object sender, EventArgs e)
{
Configuration objConfig = WebConfigurationManager.OpenWebConfiguration("~");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection("appSettings");
//Edit
if (objAppsettings != null)
{
objAppsettings.Settings["test"].Value = "newvalueFromCode";
objConfig.Save();
}
}
What will happen when you write the following code Response Cache SetNoStore
HttpCachePolicy.SetNoStore() or Response.Cache.SetNoStore
Prevents the browser from caching the ASPX page.
How to prevent a class from being inherited
In order to prevent a class in C# from being inherited, the keyword sealed is used. Thus a sealed class may not serve as a base class of any other class. It is also obvious that a sealed class cannot be an abstract class. Code below...
sealed class ClassA
{
public int x;
public int y;
}
What is difference between overloading and overriding
Overloading and Overriding both are example of polymorphism. Overriding is dynamic polymorphism while overloading is static polymorphism.
In other words, Overloading is evaluated at compile time whereas Overriding is evaluated at Run Time.
Overriding: Overriding is a changing of behavior of a class in drive class using dynamic polymorphism. For example in C# you have a class A and another class B derives from A. Class A have a virtual method abc and in class B using override you given new functionality to this method.
Overloading: Overloading is a mechanism by which we can have two or more different methods using same name.Overloading can be implemented using different parameter data types, different number of parameters, and different order of parameters























No comments:

Post a Comment