View
257
Download
0
Category
Preview:
Citation preview
8/13/2019 dotnet faqs1
1/124
(B)What is IL?
Twist :- What is MSIL or CIL , What is JIT?
(IL)Intermediate Language is also nown as MSIL (Mi!roso"t Intermediate Language) or CIL
(Common Intermediate Language)# $ll #%&T sour!e !ode is !om'iled to IL# This IL is then
!onerted to ma!hine !ode at the 'oint where the so"tware is installed, or at run-time * a Just-
In-
Time (JIT) !om'iler#
(B)What is the CL+?
ull "orm o" CL+ is Common Language +untime and it "orms the heart o" the #%&T
"ramewor#$ll Languages hae runtime and its the res'onsiilit* o" the runtime to tae !are o"
the !ode ee!ution o" the 'rogram#or eam'le .C// has MSC+T01#2LL,.B3 has
MS.B.M31#2LL , Jaa has Jaa .irtual Ma!hine et!# Similarl* #%&T has CL+#ollowing are the
res'onsiilities o" CL+
4 5arage Colle!tion :- CL+ automati!all* manages memor* thus eliminating
memor* leaes# When o6e!ts are not re"erred 5C automati!all* releases those
memor* thus 'roiding e""i!ient memor* management#
4 Code $!!ess Se!urit* :- C$S grants rights to 'rogram de'ending on the se!urit*
!on"iguration o" the ma!hine#&am'le the 'rogram has rights to edit or !reate
a new "ile ut the se!urit* !on"iguration o" ma!hine does not allow the 'rogramto delete a "ile#C$S will tae !are that the !ode runs under the enironment o"
ma!hines se!urit* !on"iguration#
4 Code .eri"i!ation :- This ensures 'ro'er !ode ee!ution and t*'e sa"et* while
the !ode runs#It 'reents the sour!e !ode to 'er"orm illegal o'eration su!h as
a!!essing inalid memor* lo!ations et!#
4 IL( Intermediate language )-to-natie translators and o'timi7er8s :- CL+ uses
JIT and !om'iles the IL !ode to ma!hine !ode and then ee!utes# CL+ also
determines de'ending on 'lat"orm what is o'timi7ed wa* o" running the IL
!ode#
(B)What is the CTS?
In order that two language !ommuni!ate smoothl* CL+ has CTS (Common T*'eS*stem)#&am'le
in .B *ou hae 9Integer and in C// *ou hae 9long these datat*'es are not !om'atile so the
inter"a!ing etween them is er* !om'li!ated# In order that two di""erent languages !an
!ommuni!ate
;
8/13/2019 dotnet faqs1
2/124
(B)What is Managed Code?
Managed !ode runs inside the enironment o" CL+ i#e# #%&T runtime#In short all IL are managed
!ode#But i" *ou are using some third 'art* so"tware eam'le .B3 or .C// !om'onent the* are
unmanaged !ode as #%&T runtime (CL+) does not hae !ontrol oer the sour!e !ode ee!ution
o" the language#
(B)What is $sseml* ?
4 $sseml* is unit o" de'lo*ment lie && or a 2LL#
4 $n asseml* !onsists o" one or more "iles (dlls, ee8s, html "iles et!#), and
re'resents a grou' o" resour!es, t*'e de"initions, and im'lementations o" those
t*'es# $n asseml* ma* also !ontain re"eren!es to other assemlies# These
resour!es, t*'es and re"eren!es are des!ried in a lo! o" data !alled a mani"est#
The mani"est is 'art o" the asseml*, thus maing the asseml* sel"-des!riing#
4 $n asseml* is !om'letel* sel"-des!riing#$n asseml* !ontains metadata
in"ormation, whi!h is used * the CL+ "or eer*thing "rom t*'e !he!ing and
se!urit* to a!tuall* inoing the !om'onents methods#$s all in"ormation is in
asseml* itsel" it is inde'endent o" registr*#This is the asi! adantage as
!om'ared to C
8/13/2019 dotnet faqs1
3/124
4 %ames'a!e !an s'an multi'le asseml*#
($)I" *ou want to iew a $sseml* how to *ou go aout it ?
Twist : What is IL2$SM ?
When it !omes to understanding o" internals nothing !an eat IL2$SM#IL2$SM asi!all*
!onerts
the whole ee or dll in to IL !ode#To run IL2$SM *ou hae to go to HC:Erogram ilesMi!roso"t
;Is *our e'erien!e "ull* in #%&T , or do *ou hae an* 'rior e'erien!e in other
mi!roso"t te!hnolog* lie .B3,.C// et!
;Can *ou gie me two re"eren!es o" *our 'reious !om'an* whom i !an !onta!t ?
1
.isual Studio #%&T 11AS2>#>BinH# %ote that i had >#> *ou hae to 'roal* !hange it
de'ending on the t*'e o" "ramewor ersion *ou hae#
I" *ou run I2$SM#&& "rom the 'ath *ou will e 'o''ed with the I2$SM ee 'rogram as
shown in "igure IL2$SM#Cli! on "ile and rowse to the res'e!tie dire!tor* "or the 2LL whose
asseml* *ou want to iew#$"ter *ou sele!t the 2LL *ou will e 'o''ed with a tree iew details
o" the 2LL as shown in "igure IL2$SM## Mani"est .iew
($) What is Mani"est?
$sseml* metadata is stored in Mani"est#Mani"est !ontains all the metadata needed to do the
"ollowing things( See igure Mani"est .iew "or more details) :
4 .ersion o" asseml*
4 Se!urit* identit*
4 S!o'e o" the asseml*
4 resole re"eren!es to resour!es and !lasses#
4 The asseml* mani"est !an e stored in either a E& "ile (an #ee or #dll) with
Mi!roso"t intermediate language (MSIL) !ode or in a stand-alone E& "ile that
!ontains onl* asseml* mani"est in"ormation#
; ae *ou heard aout our !om'an* ? Sa* "ie 'oints aout our !om'an* ? Just read atleast
on!e what !om'an* *ou are going "or ?
; Whi!h is the est 'ro6e!t *ou hae done till now ? and in what sense the 'ro6e!t was the est ?
8/13/2019 dotnet faqs1
4/124
A
(B)Where is ersion in"ormation stored o" a asseml* ?
.ersion in"ormation is stored in asseml* in mani"est#
(I)Is ersioning a''li!ale to 'riate assemlies?
.ersioning !on!e't is onl* a''li!ale to gloal asseml* !a!he (5$C) as 'riate asseml* lie in
there indiidual "olders#
(B) What is 5$C ?
Twist :- What are situations when *ou register #%&T asseml* in 5$C ?
5$C (5loal $sseml* Ca!he) is where shared #%&T asseml* reside#5$C is used in the "ollowing
situations :-
4 I" the a''li!ation has to e shared among seeral a''li!ation#
4 I" the asseml* has some s'e!ial se!urit* re=uirements lie onl* administrators
!an remoe the asseml*#I" the asseml* is 'riate then a sim'le delete o"
asseml* the asseml* "ile will remoe the asseml*#
%ote :- +egistering #%&T asseml* in 5$C !an lead to the old 'rolem o" 2LL hell#
Where C
8/13/2019 dotnet faqs1
5/124
igure:- ># Cli! on 'ro6e!t and then !li! on 9!lasslirar*> 'ro'erties menu to sign the
asseml*
4 Cli! on 'ro6e!t -- 'ro'erties and the rowse the S% "ile to the res'e!tie
"older and !om'ile the 'ro6e!t#
;Whi!h is *our "aorite .B3 or .B#%&T#####Just do not get in to arguments ?
; What8s *our "aorite .B#%&T or CN####Ere'are a di'lomati! answer#### 2o not get in to
arguments#
igure :- >#@ Cli! on Gse a e* "ile to sign the asseml* with strong name
(I)ow to add and remoe a asseml* "rom 5$C?
There are two wa*s to install #%&T asseml* in 5$C:-
4 Gsing Mi!roso"t Installer Ea!age#Kou !an get download o" installer "rom
htt':OOwww#mi!roso"t#!om#
4 Gsing 5a!util# 5oto 9.isual Studio Command Erom't and t*'e 9ga!util Pi
(asseml*Qname)#Where (asseml*Qname) is the 2LL name o" the 'ro6e!t#
; I" *ou "ail in one interiew does not mean *ou hae to disa''ointed#ee' tr*ing IT
industr* has lot in store#
; $s a interiewer alwa*s rememer that *ou will also e sitting sometimes at the other end#So
do not as an* 's*!he=uestion whi!h does not 6udge an*thing o" a !andidate#
@
(B) What is 2ela* signing ?
2uring deelo'ment 'ro!ess *ou will need strong name e*s to e e'osed to deelo'er whi!h
will is not a good 'ra!ti!e "rom se!urit* as'e!t 'oint o" iew#In su!h situations *ou !an assign the
e* later on and during deelo'ment *ou an use dela* signing
ollowing is 'ro!ess to dela* sign a asseml*:
4 irst otain *our string name e*s using S%#&
4 $nnotate the sour!e !ode "or the asseml* with two !ustom attriutes "rom
S*stem#+e"le!tion: $sseml*e*ile$ttriute, whi!h 'asses the name o" the "ile
!ontaining the 'uli! e* as a 'arameter to its !onstru!tor# $sseml*2ela*Sign$ttriute,whi!h indi!ates that dela* signing is eing used * 'assing true as a 'arameter to its
!onstru!tor# or eam'le as shown elow:
R.isual Basi!
$sseml*:$sseml*e*ile$ttriute(Hm*e*#snH)U
$sseml*:$sseml*2ela*Sign$ttriute(true)U
RCN
Rasseml*:$sseml*e*ile$ttriute(Hm*e*#snH)
Rasseml*:$sseml*2ela*Sign$ttriute(true)
The !om'iler inserts the 'uli! e* into the asseml* mani"est and reseres s'a!e in the E& "ile
"or
the "ull strong name signature# The real 'uli! e* must e stored while the asseml* is uilt so
that other assemlies that re"eren!e this asseml* !an otain the e* to store in their own
asseml*
re"eren!e#
4 Be!ause the asseml* does not hae a alid strong name signature, the eri"i!ation o"
that signature must e turned o""# Kou !an do this * using the P.r o'tion with the
Strong %ame tool#The "ollowing eam'le turns o"" eri"i!ation "or an asseml* !alled
m*$sseml*#dll#
Sn P.r m*$sseml*#dll
D
8/13/2019 dotnet faqs1
6/124
4 Just e"ore shi''ing, *ou sumit the asseml* to *our organi7ationFs signing authorit*
"or the a!tual strong name signing using the P+ o'tion with the Strong %ame tool#The
"ollowing eam'le signs an asseml* !alled m*$sseml*#dll with a strong name using
the sge*#sn e* 'air#
Sn -+ m*$sseml*#dll sge*#sn
(B)What is garage !olle!tion?
5arage !olle!tion
5arage !olle!tion is a CL+ "eature whi!h automati!all* manages memor*# Erogrammers "orget
to release the o6e!ts while !oding ##### la7iness ( +ememer in .B3 where one o" the good
'ra!ti!es is to set o6e!t to nothing)#CL+ automati!all* releases o6e!ts when the* are no longer
re"eren!ed and in use#CL+ runs on non-deterministi! to see the unused o6e!ts and !leans them#
minutes he was roaming around
8/13/2019 dotnet faqs1
7/124
the same =uestion in order to get answer "rom me (re=uirement was "or a sim'le dataase
'ro6e!t)# Beware o" su!h !om'anies and interiewers *ou an land u' no where#
JIT !om'iler is a 'art o" the runtime ee!ution enironment#
In Mi!roso"t #%&T there are three t*'es o" JIT !om'ilers:
A>
4 Ere-JIT# Ere-JIT !om'iles !om'lete sour!e !ode into natie !ode in a single !om'ilation
!*!le# This is done at the time o" de'lo*ment o" the a''li!ation#
4 &!ono-JIT# &!ono-JIT !om'iles onl* those methods that are !alled at runtime#
oweer, these !om'iled methods are remoed when the* are not re=uired#
4 %ormal-JIT# %ormal-JIT !om'iles onl* those methods that are !alled at runtime#
These methods are !om'iled the "irst time the* are !alled, and then the* are stored in
!a!he# When the same methods are !alled again, the !om'iled !ode "rom !a!he is
used "or ee!ution#
(B) What are .alue t*'es and +e"eren!e t*'es ?
.alue t*'es dire!tl* !ontain their data are either allo!ated on the sta! or allo!ated in-line in a
stru!ture#
+e"eren!e t*'es store a re"eren!e to the alueFs memor* address, and are allo!ated on the hea'#
+e"eren!e t*'es !an e sel"-des!riing t*'es, 'ointer t*'es, or inter"a!e t*'es#
.ariales that are alue t*'es ea!h hae their own !o'* o" the data, and there"ore o'erations onone ariale do not a""e!t other ariales# .ariales that are re"eren!e t*'es !an re"er to the
same
o6e!t there"ore, o'erations on one ariale !an a""e!t the same o6e!t re"erred to * another
ariale#$ll t*'es derie "rom the S*stem#
8/13/2019 dotnet faqs1
8/124
4 as the WIT !onstru!t whi!h is not in CN#
4 The .B#%&T 'art o" .isual Studio #%&T !om'iles *our !ode in the a!ground#
While this is !onsidered an adantage "or small 'ro6e!ts, 'eo'le !reating er* large
'ro6e!ts hae "ound that the I2& slows down !onsideral* as the 'ro6e!t gets larger#
$dantages o" CN
4 ML do!umentation is generated "rom sour!e !ode ut this is now een in!or'orated
in Whide*#
4 #D &!e'tion ierar!h*
%ote:- ranl* I hae alwa*s relied on using Mi!roso"t e!e'tion a''li!ation lo!s# $s
su!h I hae neer used a''li!ation e!e'tion I thin most o" the wor is done using S*steme!e'tion !lasses#
(I)What is C
8/13/2019 dotnet faqs1
9/124
4 $dding re"eren!e in .isual Studio#net#See "igure elow ($dding re"eren!e using .S#%&T
11)#Wra''er !lass is generated and 'la!ed in the 9BI% dire!tor*#
igure :- #> $dding +e"eren!e using .S#%&T 11
##%&T Intero'erailit*
A3
4 Gsing T*'e lirar* im'ort tool# Tlim'#ee *ourname#dll#
4 Gsing intero'seri!es#S*stem#runtime#Intero'seri!es names'a!e !ontains !lass
T*'eLi Conerter whi!h 'roides methods to !onert C
8/13/2019 dotnet faqs1
10/124
&nd 5et
Set(B*.al alue $s String)
EstrCustomerCode V alue
&nd Set
&nd Ero'ert*
Euli! Ero'ert* Customer%ame() $s String Im'lements
ICustomer#Customer%ame
5et
+eturn EstrCustomer%ame
&nd 5et
Set(B*.al alue $s String)
EstrCustomer%ame V alue
&nd Set
&nd Ero'ert*
Euli! Su %ew()
&nd Su&nd Class
%ote :- Sour!e !ode o" this is 'roided in C2 in C
8/13/2019 dotnet faqs1
11/124
QLoad(B*.al sender $s S*stem#
8/13/2019 dotnet faqs1
12/124
using S*stem#Colle!tions#5eneri!
using S*stem#Com'onentModel
using S*stem#2ata
using S*stem#2rawing
using S*stem#Windows#orms
using S*stem#+untime#Intero'Seri!es
Nendregion
names'a!e CShar'Code
Z
'artial !lass orm> : orm
Z
R2llIm'ort(9ernelA#dll)
stati! etern int Slee'(long dwMillise!onds)
'uli! orm>()
Z
Initiali7eCom'onent()[
'riate oid orm>QLoad(o6e!t sender, &ent$rgs e)
0>
Z
MessageBo#Show(9Starting o" 111 ms###)
Slee'(111)
MessageBo#Show(9&nd o" 111 ms###)
[
[
[(B)When we use windows $EI in #%&T is it managed or unmanaged !ode
?
Windows $EI in #%&T is unmanaged !ode#
%ote:- &en though .B3 and . C// has gone o"" still man* 'eo'le do as these old
=uestions again and again#Still there are de!ent old a''li!ation whi!h are woring with
C
8/13/2019 dotnet faqs1
13/124
o" deletion# In the methods that "ollow, the s*nta is shortened to ee' the s!o'e o" the
dis!ussion
rie" and manageale#
($) Can *ou des!rie IG%
8/13/2019 dotnet faqs1
14/124
o" 're!ious andwidth used onl* "or 'inging#
The !lient has the !ontrol to set the !om'uter whi!h will e res'onsile "or the li"etime o" the
o6e!t# That is to sa*, these o6e!ts are not !reated 6ust somewhere where the s*stem resour!es
and
a!!ess 'riileges allow "or it#
Call se!urit* is im'lemented in all "our wa*s: authenti!ation (to 'reent "alse !lients "rom
im'ersonating the true !lient), authori7ation (to insure that a !lient onl* does what it is
authori7ed
to do), data integrit* (to insure that data was not tam'ered with during transit) and data 'ria!*
(to
insure that onl* designated sour!es !an read it)# The se!urit* issues are handled as the* are on
0A
o'erating s*stems# The !lient gies the serer arious a!!ess 'riileges to a!!ess memor* or dis
s'a!e
(B)ow do we !reate 2C
8/13/2019 dotnet faqs1
15/124
ContetGtil#SetCom'lete()
[
!at!h(&!e'tion)
Z
OO Something went wrong $ort and +olla! the Transa!tion#
ContetGtil#Set$ort()
[
[
4 Com'onent deried "rom 9Seri!edCom'onent should e strong named as the*
run under C
8/13/2019 dotnet faqs1
16/124
Euli! Su 2oWor()
F Method !ontents go here#
&nd Su
&nd Class
$oe is a sam'le !ode whi!h has the 9
8/13/2019 dotnet faqs1
17/124
with a new orward e* !ontaining the alue o" this new inter"a!e I2# C)
8/13/2019 dotnet faqs1
18/124
2im 'thread $s %ew Thread($ddress
Loo'
&nd Su
$oe is a sam'le !ode whi!h shows sim'le sam'le !ode "or threading##$oe sam'le
!ode !an e "ound in 9Threading "older in C2 'roided#$oe sam'le has two methods
9Thread>() and 9Thread() whi!h are started in multi-threaded mode in orm load
eent o" the sam'le#%ote :- I" *ou run the sam'le *ou will see that sometimes the "irst thread runs "irst and
then the se!ond thread#This ha''ens e!ause o" thread 'riorities #The "irst thread is run
with highest 'riorit*#
($)ow !an we !hange 'riorit* and what the leels o" 'riorit* are
'roided * #%&T ?
Thread Eriorit* !an e !hanged * using Threadname#Eriorit* V ThreadEriorit*#ighest#In
the sam'le 'roided loo out "or !ode where the se!ond thread is ran with a high 'riorit*#
>
ollowing are di""erent leels o" Eriorit* 'roided * #%&T :-
4 ThreadEriorit*#ighest
4 ThreadEriorit*#$oe%ormal
4 ThreadEriorit*#%ormal
4 ThreadEriorit*#Below%ormal
4 ThreadEriorit*#Lowest
($)What does $ddresso" o'erator do in a!ground ?
The $ddress
8/13/2019 dotnet faqs1
19/124
has een instantiated, *ou egin the ee!ution o" the !ode * !alling the Start() method
o" the thread
($)ow !an *ou re"eren!e !urrent thread o" the method ?
HThread#CurrentThreadH re"ers to the !urrent thread running in the
method#HCurrentThreadH is a 'uli! stati! 'ro'ert*#
(I) WhatFs Thread#Slee'() in threading ?
ThreadFs ee!ution !an e 'aused * !alling the Thread#Slee' method# This method taes
an integer alue that determines how long the thread should slee'#&am'le
Thread#CurrentThread#Slee'(111)#
($)ow !an we mae a thread slee' "or in"inite 'eriod ?
Kou !an also 'la!e a thread into the slee' state "or an indeterminate amount o" time *
!alling Thread#Slee' (S*stem#Threading#Timeout#In"inite)#To interru't this slee' *ou !an
!all the Thread#Interru't method#
($) What is Sus'end and +esume in Threading ?
It is Similar to Slee' and Interru't# Sus'end allows *ou to lo! a thread until another
thread !alls Thread#+esume# The di""eren!e etween Slee' and Sus'end is that the latterdoes not immediatel* 'la!e a thread in the wait state# The thread does not sus'end until
the #%&T runtime determines that it is in a sa"e 'la!e to sus'end it# Slee' will immediatel*
'la!e a thread in a wait state#
%ote :- In threading interiews most 'eo'le get !on"used with Slee' and Sus'end#The* loo
er* similar#
($)What the wa* to sto' a long running thread ?
Thread#$ort() sto's the thread ee!ution at that moment itsel"#
($) ow do i deug thread ?
igure :- A#> 2eug thread windowThis window is onl* seen when the 'rogram is running in deug mode#In windows one o"
the window is 9Threads#
($)WhatFs Thread#Join() in threading ?
A
There are two ersions o" Thread#Join :-
4 Thread#6oin()#
4 Thread#6oin(Integer) this returns a oolean alue#
The Thread#Join method is use"ul "or determining i" a thread has !om'leted e"ore starting
another tas# The Join method waits a s'e!i"ied amount o" time "or a thread to end# I" the
thread ends e"ore the time-out, Join returns True otherwise it returns alse#
8/13/2019 dotnet faqs1
20/124
2aemon?
2aemon threadFs run in a!ground and sto' automati!all* when nothing is running
'rogram#&am'le o" a 2aemon thread is H5arage !olle!torH#5arage !olle!tor runs
until some #%&T !ode is running or else its idle#
Kou !an mae a thread 2aemon *
Thread#Isa!groundVtrue
($) When woring with shared data in threading how do *ou im'lement
s*n!hroni7ation ?
There are a somethings *ou need to e !are"ul with when using threads# I" two threads
(e#g# the main and an* worer threads) tr* to a!!ess the same ariale at the same time,
*ouFll hae a 'rolem# This !an e er* di""i!ult to deug e!ause the* ma* not alwa*s do
it at ea!tl* the same time# To aoid the 'rolem, *ou !an lo! a ariale e"ore a!!essing
it# oweer, i" two threads lo! the same ariale at the same time, *ouFll hae a deadlo!
'rolem#
0
S*n!Lo! F2o something with
&nd S*n!Lo!
(I)Can we use eents with threading ?
Kes *ou !an use eents with threads , this is one o" the te!hni=ue to s*n!hroni7e one
thread with other#
($)ow !an we now a state o" a thread?
HThreadStateH 'ro'ert* !an e used to get detail o" a thread#Thread !an hae one or
!omination o" status#S*stem#Threading#Threadstate enumeration has all the alues to
dete!t a state o" thread#Some sam'le states are Isrunning,Is$lie,sus'ended et!#
($) What is use o" Interlo!ed !lass ?Interlo!ed !lass 'roides methods * whi!h *ou !an a!hiee "ollowing "un!tionalities :-
4 in!rement .alues#
4 2e!rement alues#
4 &!hange alues etween ariales#
4 Com'are alues "rom an* thread#
in a s*n!hroni7ation mode#
&am'le :- S*stem#Threading#Interlo!ed#In!rement(Int$)
($) what is a monitor o6e!t?
Monitor o6e!ts are used to ensure that a lo! o" !ode runs without eing interru'ted *
!ode running on other threads# In other words, !ode in other threads !annot run until
!ode in the s*n!hroni7ed !ode lo! has "inished#
S*n!Lo! and &nd S*n!Lo! statements are 'roided in order to sim'li"* a!!ess to monitor
o6e!t#
($) what are wait handles ?
Twist :- What is a mute o6e!t ?
Wait handles sends signals o" a thread status "rom one thread to other thread#There are
8/13/2019 dotnet faqs1
21/124
three ind o" wait modes :-
4 Wait
8/13/2019 dotnet faqs1
22/124
+emoting and Weseri!es(B)What is an a''li!ation domain?
Ereiousl* 9E+
8/13/2019 dotnet faqs1
23/124
D
+emoting has atleast three se!tions :-
4 Common Inter"a!e whi!h will e shared etween them#
4 Serer#
4 Client#
igure :- 0#A Solution &'lorer o" +emoting Ero6e!t
In C2 9+emotingSam'le(S$
8/13/2019 dotnet faqs1
24/124
Console#WriteLine(9Serer Started####)
o6tt'Channel V %ew tt'Channel(>A0)
ChannelSeri!es#+egisterChannel(o6tt'Channel)
+emotingCon"iguration#+egisterWellnownSeri!eT*'e(5etT*'e(+emotingSerer),
9+emoteA0O+emote
8/13/2019 dotnet faqs1
25/124
Im'orts Intera!e+emoting
Module ModuleStartClient
Su Main()
2im o6tt'Channel $s %ew tt'Channel
2im o6+emoting $s Intera!e+emoting#Intera!e+emoting
ChannelSeri!es#+egisterChannel(o6tt'Channel)
o6+emoting V
CT*'e($!tiator#5etA0O+emote
8/13/2019 dotnet faqs1
26/124
($) What are the wa*s !lient !an !reate o6e!t on serer in C$< model ?
There are two wa*s * whi!h *ou !an !reate Client o6e!ts on remoting serer :-
4 $!tiator#CreateInstan!e()#
4 B* e*word 9%ew#
30
($) $re C$< state"ul in nature ?
Kes#In C$< remoting model !lient !reates a instan!e on serer and instan!e ariale set
* !lient on serer !an e retrieed again with !orre!t alue#
($) In C$< model when we want !lient o6e!ts to e !reated * 9%&W
e*word is there an* 're!autions to e taen ?
+emoting Clients and +emoting Serer !an !ommuni!ate e!ause the* share a !ommon
!ontra!t * im'lementing Shared Inter"a!e or Base Class ($s seen in 'reious eam'les)#
But a!!ording to
8/13/2019 dotnet faqs1
27/124
($) What is LeaseTime,S'onsorshi'Time ,+enewonCallTime and
LeaseManagerEollTime?
This is a er* im'ortant =uestion "rom 'ra!ti!al im'lementation 'oint o" iew#Com'anies
who hae s'e!i"i! re=uirement "or +emoting 'ro6e!t8s will e'e!t this =uestion to e answered#
In normal #%&T enironment o6e!ts li"etime is managed * garage !olle!tor#But in
remoting enironment remote !lients !an a!!ess o6e!ts whi!h is out o" !ontrol o" garage
!olle!tor#5arage !olle!tor oundar* is limited to a single EC on whi!h "ramewor is
running , an* remote !lient a!ross 'h*si!al EC is out o" !ontrol o" 5C (5arage Colle!tor)#
This !onstraint o" garage !olle!tor leads to a new wa* o" handling li"etime "or remoting
o6e!ts , * using !on!e't !alled as 9LeaseTime#&er* serer side o6e!t is assigned *
de"ault a 9LeaseTime o" "ie minutes#This leasetime is de!reased at !ertain interals#$gain
"or eer* method !all a de"ault o" two minutes is assigned#When i sa* method !all means
eer* !all made "rom !lient#This is !alled as 9+enewal) V >1 minutes (&er*thing is in
minutes)
33
When total o6e!t li"etime is redu!ed to 7ero , it =ueries the s'onsor that should the
o6e!t e destro*ed#S'onsor is a o6e!t whi!h de!ides should o6e!t Li"etime e
renewed#So it =ueries an* registered s'onsors with the o6e!t , i" does not "ind an* then
the o6e!t is mared "or garage !olle!tion#$"ter this garage !olle!tion has whole !ontrol
on the o6e!t li"etime#I" we do not "oresee how long a o6e!t will e needed s'e!i"* the
9S'onsorShi'Time
8/13/2019 dotnet faqs1
28/124
whi!h we where 'roiding through !ode#
!on"igurationU
s*stem#runtime#remotingU
a''li!ation nameVSererU
seri!eU
wellnown
3@
modeVSingleCall
t*'eVSerer#ClsSerer, Serer
o6e!tGriV+emote
8/13/2019 dotnet faqs1
29/124
o6Seri!e&ntries V
+emotingCon"iguration#5et+egisteredWellnownClientT*'es()
Io6Common V $!tiator#5et
8/13/2019 dotnet faqs1
30/124
8/13/2019 dotnet faqs1
31/124
We Seri!e 2es!ri'tion Language (WS2L)is a WAC s'e!i"i!ation whi!h de"ines ML
grammar "or des!riing We Seri!es#ML grammar des!ries details su!h as:-
4 Where we !an "ind the We Seri!e (its G+I)
4 What methods and 'ro'erties that seri!e su''orts
4 2ata t*'e su''ort#
4 Su''orted 'roto!ols
In short its a ile o" what the weseri!e !an do#Clients !an !onsume this WS2L and
uild 'ro* o6e!ts that !lients use to !ommuni!ate with the We Seri!es# ull WS2L
s'e!i"i!ation is aailale at htt':OOwww#wA#orgOT+Owsdl#
($) What the di""erent 'haseOste's o" a!=uiring a 'ro* o6e!t in
Weseri!e ?
The "ollowing are the di""erent ste's needed to get a 'ro* o6e!t o" a weseri!e at the
!lient side :-
4 Client !ommuni!ates to G2I node "or WeSeri!e either through rowser or
G22IFs 'uli! we seri!e#
4 G2II res'onds with a list o" weseri!e#4 &er* seri!e listed * weseri!e has a G+I 'ointing to 2ISC< or WS2L
do!ument#
A
4 $"ter 'arsing the 2ISC< do!ument, we "ollow the G+I "or the WS2L do!ument
related to the weseri!e whi!h we need#
4 Client then 'arses the WS2L do!ument and uilds a 'ro* o6e!t whi!h !an
!ommuni!ate with Weseri!e#
(B) What is "ile etension o" Weseri!es ?
#$SM is etension "or Weseri!es#
%ote :- $"ter this we are going to deal with a sam'le o" weseri!e#In .S11 we'ro6e!tis !reated "rom the menu itsel" as !om'ared to 11A where it was 'resent in the e'lorer#
0
igure :- 0#@ Create We 'ro6e!t menu in .S11
(B)Whi!h attriute is used in order that the method !an e used as
WeSeri!e ?
WeMethod attriute has to e s'e!i"ied in order that the method and 'ro'ert* !an e
treated as WeSeri!e#
($) What are the ste's to !reate a weseri!e and !onsume it ?
%ote :- or this =uestion this oo will mae a attem't * !reating a sim'le weseri!e and
e'laining ste's to a!heie it#$ sim'le weseri!e will e !reated whi!h taes two numer
and gies addition result o" the two numer#In C2 sam'le weseri!e 'ro6e!t with "older
name 9MathsWeSeri!e is 'roided and same will e e'lained elow# 2e"initel* the
interiewer will not e'e!t su!h a detail answer ut this oo will e'lain *ou in detail so
that *ou are on right tra! during interiew#
This weseri!e will add two numers and gie to the !alling !lient#$ll the elow ste's
are a!!ording to .S11 eta editor :-
8/13/2019 dotnet faqs1
32/124
4 irst !reate a wesite * !li!ing on ile -- %ew WeSite#
4 rom 9.isual Studio Installed Tem'lates !li! on 9$s'#%&T We Seri!e#See
"igure elow#%ame the "igure as 9Maths We Seri!e#
igure :- 0#D Create WeSeri!e Ero6e!t
3
4 B* de"ault the #%&T editor has made a de"ault weseri!e method !alled as
HelloWordH whi!h returns a string datat*'e#LetFs rename HSeri!e#H to
HMaths#H and HSeri!e#asmH to HMaths#asmH#Let8s re'la!e the
9elloWorld with "ollowing !ode elow :-
WeMethod()U Q
Euli! un!tion $ddTwo%umers(B*.al %umer> $s Integer, B*.al
%umer $s Integer) $s Integer
+eturn %umer> / %umer
&nd un!tion
igure :- 0#>1 +ename all *our de"ault 9Seri!e to 9Maths4
4 $"ter the weseri!e is done !li! on add Were"eren!e#%ormall* "or
!om'onents we do a 9$dd +e"eren!e and "or Weseri!es we do 9$dd We
+e"eren!e#
igure :- 0#>> Cli! on $dd We +e"eren!e
@
4 Kou will e shown with a list o" weseri!es whi!h are nown to the
solutions#$s we are looing "or our 9Maths weseri!e whi!h eist in the same
solution , we !li! 9Weseri!es in this solution#
Digure :- 0#> List o" weseri!es "or rowsing
4 Kour editor has lo!ated the 9Maths weseri!e#Sele!t the weseri!e#
igure :- 0#>A Solution showing the aailailit* o" Maths Weseri!e#
@1
@>
4 $"ter *ou hae !li!ed on 9Maths weseri!e *ou will see a sear!h 'rogress
ar as shown in "igure elow#This 'ro!ess will start the weseri!e , re"eren!e it
and !reate a 'ro* "or the !lient , so that using it !lient !an asor the
weseri!e#
igure :- 0#>0 Starting the weseri!e and !reating the 'ro* "or *our solution#
@
4 inall* *ou are ale to see *our weseri!e whi!h is read* "or use#Cli! on
$dd +e"eren!e and *ou will see a 9Lo!alhost re"eren!e in *our #%&T solution#
igure :- 0#> Starting the weseri!e and !reating the 'ro* "or *our solution#
4 We need to mae a !lient who will asor this 9Maths Weseri!e#$dd
9Weseri!eClient#as' and !reate a GI as shown elow#In the utton !li!
'ut in the "ollowing !ode#Lo!alost#ClsMaths is the 'ro* o6e!t * whi!h
8/13/2019 dotnet faqs1
33/124
*ou !an mae !alls to the weseri!e#
Su !mdCal!ulateQCli!(B*.al sender $s
8/13/2019 dotnet faqs1
34/124
(B) What is a''li!ation o6e!t ?
$''li!ation o6e!t !an used in situation where we want data to e shared a!ross users
gloall*#
(I)What8s the di""eren!e etween Ca!he o6e!t and a''li!ation o6e!t ?
The main di""eren!e etween the Ca!he and $''li!ation o6e!ts is that the Ca!he o6e!t
'roides !a!he-s'e!i"i! "eatures, su!h as de'enden!ies and e'iration 'oli!ies#
(I)ow !an get a!!ess to !a!he o6e!t ?
The Ca!he o6e!t is de"ined in the S*stem#We#Ca!hing names'a!e# Kou !an get a re"eren!e
to the Ca!he o6e!t * using the Ca!he 'ro'ert* o" the tt'Contet !lass in the
S*stem#We names'a!e or * using the Ca!he 'ro'ert* o" the Eage o6e!t#
($)What are de'enden!ies in !a!he and t*'es o" de'enden!ies ?
When *ou add an item to the !a!he, *ou !an de"ine de'enden!* relationshi's that !an
"or!e that item to e remoed "rom the !a!he under s'e!i"i! a!tiities o"
de'enden!ies#&am'le i" the !a!he o6e!t is de'endent on "ile and when the "ile data
!hanges *ou want the !a!he o6e!t to e u'date#ollowing are the su''orted de'enden!*
:-
4 ile de'enden!* :- $llows *ou to inalidate a s'e!i"i! !a!he item when a dis
ased "ile or "iles !hange#
4 Time-ased e'iration :- $llows *ou to inalidate a s'e!i"i! !a!he itemde'ending on 'rede"ined time#
4 e* de'enden!* :-$llows *ou to inalidate a s'e!i"i! !a!he item de'ending
when another !a!hed item !hanges#
# Ca!hing Con!e'ts
@
(E)Can *ou show a sim'le !ode showing "ile de'enden!* in !a!he ?
Eartial Class 2e"aultQas'
Euli! Su dis'la*$nnoun!ement()
2im announ!ement $s String
I" Ca!he(9announ!ement) Is %othing Then
2im "ile $s %ew QS*stem#I
8/13/2019 dotnet faqs1
35/124
"ile whi!h is l*ing in a''li!ation 'ath o" the we dire!tor*#$oe method "irst !he!s is
the Ca!he o6e!t nothing , i" the !a!he o6e!t is nothing then it moes "urther to load the
!a!he data "rom the "ile#Wheneer the "ile data !hanges the !a!he o6e!t is remoed and
set to nothing#
($) What is Ca!he Calla! in Ca!he ?
Ca!he o6e!t is de'endent on its de'enden!ies eam'le "ile ased , time ased et!#Ca!he
items remoe the o6e!t when !a!he de'enden!ies !hange#$SE#%&T 'roides !a'ailit*
to ee!ute a !alla! method when that item is remoed "rom !a!he#
@3
($) What is s!aenging ?
When serer running *our $SE#%&T a''li!ation runs low on memor* resour!es , items
are remoed "rom !a!he de'ending on !a!he item 'riorit*#!a!he item 'riorit* is set when
*ou add item to !a!he#BK setting the !a!he item 'riorit* !ontrols whi!h items s!aenging
is remoed "irst#
(B) What are di""erent t*'es o" !a!hing using !a!he o6e!t o" $SE#%&T?
Kou !an use two t*'es o" out'ut !a!hing to !a!he in"ormation that is to e transmitted to
and dis'la*ed in a We rowser:
4 Eage
8/13/2019 dotnet faqs1
36/124
4 $SE session state is de'endent on IIS 'ro!ess er* heail*#So i" IIS restarts
$SE session ariales are also re!*!led#$SE#%&T session !an e inde'endent
o" the hosting enironment thus $SE#%&T session !an maintained een i" IIS
reoots#
4 $SE session state has no inherent solution to wor with We arms#$SE#%&T
session !an e stored in state serer and S\L S&+.&+ whi!h !an su''ort
multi'le serer#
4 $SE session onl* "un!tions when rowser su''orts !ooies#$SE#%&T session
!an e used with rowser side !ooies or inde'endent o" it#
(B) Whi!h arious modes o" storing $SE#%&T session ?
4 InEro!:- In this mode Session state is stored in the memor* s'a!e o" the
$s'netQw'#ee 'ro!ess#This is the de"ault setting#I" the IIS reoots or we
a''li!ation restarts then session state is lost#
@@
4 StateSerer:-In this mode Session state is seriali7ed and stored in a se'arate
'ro!ess ($s'netQstate#ee) there"ore, the state !an e stored on a se'arate
!om'uter(a state serer)#
4 S\L S&+.&+:- In this mode Session state is seriali7ed and stored in a S\L
Serer dataase#Session state !an e s'e!i"ied in sessionStateU element o" a''li!ation !on"iguration
"ile#Gsing State Serer and S\L S&+.&+ session state !an e shared a!ross we "arms
ut note this !omes at s'eed !ost as $SE#%&T needs to seriali7e and deseriali7e data oer
networ again and again#
($) Is SessionQ&nd eent su''orted in all session modes ?
SessionQ&nd eent o!!urs onl* in 9In'ro! mode#State Serer and 9S\L S&+.&+
do not hae SessionQ&nd eent#
($) What are the 're!autions *ou will tae in order that StateSerer Mode
wor 'ro'erl* ?
ollowing are the things to rememer so that StateSerer Mode wors 'ro'erl* :-
4 StateSerer mode session data is stored in a di""erent 'ro!ess so *ou mustensure that *our o6e!ts are seriali7ale#
4 ma!hinee*U elements in We#!on"ig should e indenti!al a!ross all
serers#So this ensures that en!r*'tion "ormat is same a!ross all !om'uters#
4 IIS metaase (LMWAS.C) must e identi!al a!ross all serers in that
"arm#
($) What are the 're!autions *ou will tae in order that S\LS&+.&+
Mode wor 'ro'erl* ?
ollowing are the things to rememer so that S\LS&+.&+ Mode wors 'ro'erl* :-
4 S\LS&+.&+ mode session data is stored in a di""erent 'ro!ess so *ou must
ensure that *our o6e!ts are seriali7ale#
4 IIS metaase (LMWAS.C) must e indenti!al a!ross all serers in that
"arm#
@D
4 B* de"ault Session o6e!ts are stored in 9Tem'd , *ou !an !on"igure it store
outside 9Tem'2B * running mi!roso"t 'roided S\L s!ri't#
%ote :- 9Tem'2B dataase is re-!reated a"ter S\L S&+.&+ !om'uter reoot#I" *ou
want to maintain session state with eer* reoot est is to run S\L S!ri't and store session
o6e!ts outside 9Tem'2B dataase#
($) Where do *ou s'e!i"* session state mode in $SE#%&T ?
sessionState modeVS\LSerer
8/13/2019 dotnet faqs1
37/124
stateConne!tionStringVt!'i'V>D#>3@#>#>:000H
s=lConne!tionStringVdata sour!eV>D#>3@#>#> Integrated
Se!urit*VSSEI
!ooielessV"alse
timeoutV1H
OU
$oe is sam'le session state mode s'e!i"ied "or S\L S&+.&+#
(B) What are the other wa*s *ou !an maintain state ?
8/13/2019 dotnet faqs1
38/124
D>
4 .iew state is good "or !a!hing data in We "arm !on"igurations e!ause the
data is !a!hed on the !lient#
ollowing are limitation o" using .iewstate:-
4 Eage loading and 'osting 'er"orman!e de!reases when large alues are
stored e!ause iew state is stored in the 'age#
4 $lthough iew state stores data in a hashed "ormat, it !an still e tam'ered
with e!ause it is stored in a hidden "ield on the 'age# The in"ormation in the
hidden "ield !an also e seen i" the 'age out'ut sour!e is iewed dire!tl*,
!reating a 'otential se!urit* ris#
Below is sam'le o" storing alues in iew state#
this#.iewStateRH&nterTimeH V 2ateTime#%ow#ToString()
(B) ow an *ou use idden "rames to !a!he !lient data ?
This te!hni=ue is im'lemented * !reating a idden "rame in 'age whi!h will !ontain
*our data to e !a!hed#
+$M&S&T !olsVH>11_,;,;HU
+$M&S&T rowsVH>11_HU
+$M& sr!VHdataQo"Q"rame>#htmlHUO+$M&S&TU
+$M& sr!VHdataQo"QhiddenQ"rame#htmlHU+$M& sr!VHdataQo"QhiddenQ"rame#htmlH "rameorderVH1H noresi7e
s!rollingVH*esHU
O+$M&S&TU
$oe is a sam'le o" hidden "rames where the "irst "rame 9dataQo"Q"rame>#html is isile
and the remaining "rames are hidden * giing whole !ol se!tion to "irst "rame# See allo!ation
where >11 _ is allo!ated to "irst "rame and remaining "rames thus remain hidden#
(I) What are ene"its and Limitation o" using idden "rames?
ollowing are the ene"its o" using hidden "rames:
4 Kou !an !a!he more than one data "ield#
D
4 The ailit* to !a!he and a!!ess data items stored in di""erent hidden "orms#4 The ailit* to a!!ess JS!ri't ariale alues stored in di""erent "rames i" the*
!ome "rom the same site#
The limitations o" using hidden "rames are:
4 idden "rames are not su''orted on all rowsers#
4 idden "rames data and e tam'ered thus !reating se!urit* hole#
(I) What are ene"its and Limitation o" using Cooies?
ollowing are ene"its o" using !ooies "or state management :-
4 %o serer resour!es are re=uired as the* are stored in !lient#
4 The* are light weight and sim'le to use
ollowing are limitation o" using !ooies :-
4 Most rowsers 'la!e a 01D3-*te limit on the si7e o" a !ooie,although su''ort
"or @>D-*te !ooies is e!oming more !ommon in the new rowser and
!lient-dei!e ersions aailale toda*#
4 Some users disale their rowser or !lient dei!e8s ailit* to re!eie !ooies,
there* limiting the use o" !ooies#
4 Cooies !an e tam'ered and thus !reating a se!urit* hole#
4 Cooies !an e'ire thus leading to in!onsisten!*#
Below is sam'le !ode o" im'lementing !ooies
+e=uest#Cooies#$dd(%ew tt'Cooie(9name, 9user>))
(I) What is \uer* String and What are ene"its and Limitation o" using
8/13/2019 dotnet faqs1
39/124
\uer* Strings?
$ =uer* string is in"ormation sent to the serer a''ended to the end o" a 'age G+L#
ollowing are the ene"its o" using =uer* string "or state management:-
4 %o serer resour!es are re=uired# The =uer* string is !ontained in the TTE
re=uest "or a s'e!i"i! G+L#
DA
4 $ll rowsers su''ort =uer* strings#
ollowing are limitations o" =uer* string :-
4 \uer* string data is dire!tl* isile to user thus leading to se!urit* 'rolems#-
4 Most rowsers and !lient dei!es im'ose a -!hara!ter limit on G+L length#
Below is a sam'le 9Login =uer* string 'assed in G+L htt':OOwww#=uer*string#!omO
login#as'?loginVtesting#This =uer*string data !an then e re=uested later * using
+e=uest#\uer*String(9login)#
11 m s'eed and urgent raes#
(B) What are di""erent 'ro'erties 'roided *
8/13/2019 dotnet faqs1
40/124
D
$stra!tion
It allows !om'le real world to e re'resented in sim'li"ied manner#&am'le !olor is
astra!ted to +5B#B* 6ust maing the !omination o" these three !olors we !an a!hiee
an* !olor in world#It8s a model o" real world or !on!e't#
&n!a'sulation
The 'ro!ess o" hiding all the internal details o" an o6e!t "rom the outside world#
Communi!ation using messages
When a''li!ation wants to a!hiee !ertain tas it !an onl* e done using !omination o"
o6e!ts#$ single o6e!t !an not do all the tas#&am'le i" we want to mae order 'ro!essing
"orm# We will use Customer o6e!t ,
8/13/2019 dotnet faqs1
41/124
%ote:- The "ollowing e'lanation is "or .B#%&T
Inheritan!e is a!hieed * using 9Inherits e*word in .B#%&T (or CN it is 9:)#Sim'le
Sam'le is 'roided in C2 "or understanding inheritan!e in "older
9Windows$''li!ationInheritan!e#There are two !lasses one is the 'arent 9ClsEarent
and se!ond is the !hild 9ClsChild#Earent !lass has a string whi!h has to 'arsed "or 6un
data 9` and 9O#ClsEarent has the "un!tionalit* whi!h 'arses onl* !leans u'
9`#ClsChild then inherits "rom 'arent and adds etra "un!tionalit* * 'arsing 9O#
Euli! Class ClsEarent
Erote!ted str2ata $s String V 96sdh6`dadadOOOa6dhs6ad
Euli! un!tion Earse() $s String
2im Estr2ata $s String
Estr2ata V str2ata
Estr2ata V +e'la!e(Estr2ata, 9`, 9)
+eturn Estr2ata
&nd un!tion
Euli! un!tion 5et$!tualString() $s String+eturn str2ata
&nd un!tion
&nd Class
$oe is the sour!e whi!h 'arses onl* 9` o" str2ata ariale#
; What gies *our greatest satis"a!tion in so"tware 'ro"ession ?
D
Euli! Class ClsChild
Inherits ClsEarent
X this is !hild and a s'e!ial 'arse "un!tion is added whi!h will
also 'arse 9OEuli! un!tion EarseBa!Slash()
2im Estr2ata $s String
Estr2ata V Me#Earse()
Estr2ata V +e'la!e(Estr2ata, 9O, 9)
+eturn Estr2ata
&nd un!tion
&nd Class
$oe is the sour!e !ode "or 9ClsChild whi!h does the remaining wor#It adds etra
"un!tionalit* * 'arsing 9O 6un !hara!ter8s o" the data#
%ote:- Strdata was a!!essile onl* e!ause it was de"ined as 'rote!ted in the 'arent !lass#
igure :- 3#> Inheritan!e in a!tion
(I) What are astra!t !lasses ?
ollowing are "eatures o" a astra!t !lass :-
4 Kou !an not !reate a o6e!t o" astra!t !lass
; ow would *ou des!rie *oursel" ?
D@
4 $stra!t !lass is designed to a!t as a ase !lass (to e inherited * other !lasses)#
8/13/2019 dotnet faqs1
42/124
$stra!t !lass is a design !on!e't in 'rogram deelo'ment and 'roides a
ase u'on whi!h other !lasses are uilt#
4 $stra!t !lasses are similar to inter"a!es# $"ter de!laring an astra!t !lass, it
!annot e instantiated on itFs own, it must e inherited#
4 In .B#%&T astra!t !lasses are !reated using 9MustInherit e*word#In CN
we hae 9$stra!t e*word#
4 $stra!t !lasses !an hae im'lementation or 'ure astra!t methods whi!h
should e im'lemented in the !hild !lass#
%ote:- In order to understand the !on!e't sim'le sam'le o" add and multi'l* "un!tionalit*
is im'lemented in 9Windows$stra!t "older in C2#
rom interiew 'oint o" iew 6ust sa*ing using 9MustInherit e*word is more than enough
to !onin!e that *ou hae used astra!t !lasses#But to !lear sim'le "undamental let8s tr*
to understand the sam'le !ode#There are two !lasses one is 9Cls$stra!t !lass and other
is 9ClsChild !lass#Cls$stra!t !lass is a astra!t !lass as *ou !an see the mustinherit
e*word#It has one im'lemented method 9$dd and other is astra!t method whi!h has
to e im'lemented * !hild !lass 9Multi'l*%umer#In the !hild !lass we inherit theastra!t !lass and im'lement the multi'l*numer "un!tion#
2e"initel* this sam'le does not tae out a!tuall* how things are im'lemented in lie
'ro6e!ts#Basi!all* *ou 'ut all *our !ommon "un!tionalities or hal" im'lemented
"un!tionalit* in 'arent astra!t !lass and later let !hild !lass de"ine the "ull "un!tionalit*
o" the astra!t !lass#&am'le i alwa*s use astra!t !lass with all m* S&T 5&T 'ro'erties
o" o6e!t in astra!t !lass and later mae s'e!iali7e !lasses "or insert,u'date,delete "or
the !orres'onding entit* o6e!t#
Euli! MustInherit Class Cls$stra!t
X use the mustinherit !lass to de!lare the !lass as astra!t
Euli! un!tion $dd(B*.al intnum> $s Integer, B*.al intnum $sInteger) $s Integer
+eturn intnum> / intnum
&nd un!tion
X le"t this se!on" "un!tion to e !om'leted * the inheriting
!lass
Euli! Must $s
Integer, B*.al intnum $s Integer) $s Integer
+eturn intnum> ; intnum
&nd un!tion
8/13/2019 dotnet faqs1
43/124
&nd Class
igure :- 3# $stra!t !lasses in a!tion
M* attitude towards astra!t !lass has een that i 'ut all m* !ommon "un!tionalit* in
astra!t !lass#
(B) What8s a Inter"a!e ?
Inter"a!e is a !ontra!t that de"ines the signature o" the "un!tionalit*#So i" a !lass is
im'lementing a inter"a!e it sa*s to the outer world , that it 'roides s'e!i"i! ehaior #
&am'le i" a !lass is im'lementing Idis'osale inter"a!e that means it has a "un!tionalit*
to release unmanaged resour!es # %ow eternal o6e!ts using this !lass nows that it has
!ontra!t * whi!h it !an dis'ose unused unmanaged o6e!ts#
4 Single Class !an im'lement multi'le inter"a!es#
4 I" a !lass im'lements a inter"a!e then it has to 'roide im'lementation to all
its methods#
>11
%ote:- In C2 sam'le 9WindowsIntera!e is 'roided , whi!h has a sim'le inter"a!e
im'lemented#In sam'le there are two "iles#1>
($) What is di""eren!e etween astra!t !lasses and
inter"a!es?
ollowing are the di""eren!es etween astra!t and inter"a!es :-
4 $stra!t !lasses !an hae !on!rete methods while inter"a!es hae no methods
im'lemented#
4 Inter"a!es do not !ome in inheriting !hain , while astra!t !lasses !ome in
inheritan!e#
(B) What is a delegate ?
2elegate is a !lass that !an hold a re"eren!e to a method or a "un!tion#2elegate !lass has
a signature and it !an onl* re"eren!e those methods whose signature is !om'liant with the
!lass#2elegates are t*'e-sa"e "un!tions 'ointers or !alla!s#
8/13/2019 dotnet faqs1
44/124
Below is a sam'le !ode whi!h shows a eam'le o" how to im'lement delegates#
Euli! Class rm2elegates
Inherits S*stem#Windows#orms#orm
Euli! 2elegate Su 2elegate$ddString()
Eriate Su rm2elegatesQLoad(B*.al sender $s S*stem#
8/13/2019 dotnet faqs1
45/124
>1A
Euli! Class rmWith&ents
Inherits S*stem#Windows#orms#orm
Eriate With&ents mo6ClsWith&ents $s %ew ClsWith&ents()
Eriate Su rmWith&entsQLoad(B*.al sender $s S*stem#
8/13/2019 dotnet faqs1
46/124
&nd Class
; Wh* should i hire *ou ?
>1
igure :- 3#3 Shadowing in $!tion
($) What8s di""eren!e etween Shadowing and
13
Just imagine one o" *our !lients doing this
!#*7Calla! V null
This will reset all *our delegates to nothing and *ou hae to ee' "iguring where the error
is#
(B) I" we inherit a !lass do the 'riate ariales also get
inherited ?Kes the ariales are inherited ut !an not e a!!essed dire!tl* * the !lass inter"a!e#
(B) What are di""erent a!!essiilit* leels de"ined in
#%&T ?
ollowing are the "ie leels o" a!!ess modi"iers :-
4 Eriate :
8/13/2019 dotnet faqs1
47/124
e*word#This a!ts onl* as ase t*'e and !an not e inherited an* "urther#Kou !an not
!reate a o6e!t o" a !lass whi!h is mared as 9MustInherit#
;What hae *our learnt "rom *our 'ast 'ro6e!t e'erien!es ?
>1
(I) Wh* !an not *ou s'e!i"* a!!essiilit* modi"ier in
Inter"a!e ?
$ll elements in Inter"a!e should e 'uli!#So * de"ault all inter"a!e elements are 'uli!
* de"ault#
($) What are similarities etween Class and stru!ture ?
ollowing are the similarities etween !lasses and stru!tures :-
4 Both !an hae !onstru!tors, methods, 'ro'erties, "ields, !onstants,
enumerations, eents, and eent handlers#
4 Stru!tures and !lasses !an im'lement inter"a!e#
4 Both o" them !an hae !onstru!tors without 'arameter and with 'arameter#
4 Both !an hae delegates and eents#
($) What8s the di""eren!e etween Class andstru!ture8s ?
ollowing are the e* di""eren!es etween them :-
4 Stru!ture are alue t*'es and !lasses are re"eren!e t*'es#So stru!tures use
sta! and !lasses use hea'#
4 Stru!tures memers !an not e de!lared as 'rote!ted , ut !lass memers !an
e#Kou !an not do inheritan!e in stru!tures#
4 Stru!tures do not re=uire !onstru!tors while !lasses re=uire#
4 1@
Stati!OShared !lasses are used when a !lass 'roides "un!tionalit* whi!h is not s'e!i"i! to
an* instan!e#In short i" *ou want a o6e!t to e shared etween multi'le instan!es *ou
will use a stati!OShared !lass#
ollowing are "eatures o" Stati!OShared !lasses :-
4 The* !an not e instantiated#B* de"ault a o6e!t is !reated on the "irst method
!all to that o6e!t#
4 Stati!OShared !lasses !an not e inherited#
4 Stati!OShared !lasses !an hae onl* stati! memers#
4 Stati!OShared !lasses !an hae onl* stati! !onstru!tor#
%ote :- In C2 there is a "older 9WindowsShared whi!h has a sam'le !ode "or shared
ariales#Below is a sni''et#It has a 9$ddCount "un!tion whi!h in!rements a stati!
9intCount ariale#In "orm there are two uttons whi!h !reates a new o6e!t and dis'la*s
the !ount o" the stati! ariale#&en though the o6e!t is !reated and destro*ed , the ariale
8/13/2019 dotnet faqs1
48/124
alues does not !hange#It retains its old alue#
Euli! Class ClsShared
Shared intCount $s Integer
Euli! un!tion $ddCount() $s Integer
intCount V intCount / >
+eturn intCount
&nd un!tion
&nd Class
Euli! Class rmSharedClasses
Inherits S*stem#Windows#orms#orm
Eriate Su CmdInstan!e>QCli!(B*.al sender $s S*stem##Cli!
2im 'o6ClsShared $s %ew ClsShared()
MessageBo#Show(9The !ount at this moment is
'o6ClsShared#$ddCount#ToString())
&nd SuEriate Su CmdInstan!eQCli!(B*.al sender $s S*stem#
8/13/2019 dotnet faqs1
49/124
($) What8s a ashTale ?
Twist :- What8s di""eren!e etween ashTale and $rra*List ?
Kou !an a!!ess arra* using I%2& alue o" arra* , ut how man* times *ou now the
real alue o" inde#ashtale 'roides wa* o" a!!essing the inde using a user identi"ied
&K alue , thus remoing the I%2& 'rolem#
($) What are =ueues and sta!s ?
\ueue is "or "irst-in, "irst-out (I
8/13/2019 dotnet faqs1
50/124
&nd Class
; I leae this to the readers######
(B)What8s the signi"i!an!e o" inali7e method in #%&T?
#%&T 5arage !olle!tor does almost all !lean u' a!tiit* "or *our o6e!ts# But unmanaged
resour!es (e: - Windows $EI !reated o6e!ts, ile, 2ataase !onne!tion o6e!ts, C
whi!h !an e oerridden and !lean u' !ode "or unmanaged resour!es !an e 'ut in this
se!tion#
($)Wh* is it 're"erred to not use "inali7e "or !lean u'?
Erolem with "inali7e is that garage !olle!tion has to mae two rounds in order to remoe
o6e!ts whi!h hae "inali7e methods#
Below "igure will mae things !lear regarding the two rounds o" garage !olle!tion rounds
'er"ormed "or the o6e!ts haing "inali7ed methods#
In this s!enario there are three o6e!ts , >A
igure :- 3#@ 5arage !olle!tion in a!tions
(I)ow !an we su''ress a "inali7e method?
5C#Su''ressinali7e ()
(B)What8s the use o" 2ISE
8/13/2019 dotnet faqs1
51/124
%ote :- I admire this =uestion#
Call the 2is'ose method in inali7e method and in 2is'ose method su''ress the "inali7e
method using 5C#Su''ressinali7e# Below is the sam'le !ode o" the 'attern# This is the
est wa* we do !lean our unallo!ated resour!es and *es not to "orget we do not get the hit
o" running the 5arage !olle!tor twi!e#
%ote:- It will su''ress the "inali7e method thus aoiding the two tri'#
Euli! Class ClsTesting
Im'lements I2is'osale
Euli!
8/13/2019 dotnet faqs1
52/124
S*stem#String is immutale S*stem#StringBuilder !an hae mutale string where a ariet*
o" o'erations !an e 'er"ormed#
$SE#%&T
(B) What8s the se=uen!e in whi!h $SE#%&T eents are'ro!essed ?
ollowing are the se=uen!e in whi!h the eents o!!ur :-
4 EageQInit#
4 EageQLoad#
4 Control eents
4 EageQGnload eent#
EageQinit eent onl* o!!urs when "irst time the 'age is started , ut EageQLoad o!!urs in
suse=uent re=uest o" the 'age#
(B) In whi!h eent are the !ontrols "ull* loaded ?
EageQload eent guarantees that all !ontrols are "ull* loaded#Controls are also a!!essed in
EageQInit eents ut *ou will see that iewstate is not "ull* loaded during this eent#
(B) ow !an we identi"* that the Eage is EostBa! ?
Eage o6e!t has a 9IsEostBa! 'ro'ert* whi!h !an e !he!ed to now that is the 'age
'osted a!#
(B) ow does $SE#%&T maintain state in etween
suse=uent re=uest ?
+e"er !a!hing !ha'ter#
($) What is eent uling ?
Serer !ontrols lie 2atagrid , 2ataList , +e'eater !an hae other !hild !ontrols inside
them#&am'le 2ata5rid !an hae !omo o inside datagrid#These !hild !ontrol do not
raise there eents * themseles , rather the* 'ass the eent to the !ontainer 'arent
(whi!h !an e a datagrid , datalist , re'eater) , whi!h 'assed to the 'age as 9ItemCommand
eent#
>>
(B) ow do we assign 'age s'e!i"i! attriutes ?
Eage attriutes are s'e!i"ied using the `Eage dire!tie#
($) $dministrator wants to mae a se!urit* !he! that no
one has tam'ered with .iewState , how !an we ensure this ?
Gsing the `Eage dire!tie &nale.iewStateMa! to True#(B) What8s the use o" +egister dire!ties ?
`+egister dire!tie in"orms the !om'iler o" an* !ustom serer !ontrol added to the
'age#
(B) What8s the use o" Smart%aigation 'ro'ert* ?
It8s a "eature 'roided * $SE#%&T to 'reent "li!ering and redrawing when the 'age is
'osted a!#
%ote:- This is onl* su''orted "or I& rowser#Ero6e!t8s who hae rowser !om'atiilit* as
8/13/2019 dotnet faqs1
53/124
re=uirement hae to thin some other wa*s o" aoiding "li!ering#
(B) What is $''Setting Se!tion in 9We#Con"ig "ile ?
We#!on"ig "ile de"ines !on"iguration "or a we'ro6e!t#Gsing 9$''Setting se!tion we !an
de"ine user de"ined alues#&am'le elow de"ined is 9Conne!tionString se!tion whi!h
will e used through out the 'ro6e!t "or dataase !onne!tion#
!on"igurationU
a''SettingsU
add e*VHConne!tionStringH alueVHsererV*7'wdVwwwdataaseVtestingH OU
Oa''SettingsU
(B) Where is .iewState in"ormation stored ?
In TML idden ields#
>>@
(I) What8s the use o" ` >D
Custom.alidator
Gsed to de"ine Gser2e"ined alidation#
.alidationSummar*
2is'la*s summar* o" all !urrent alidation errors#
%ote:- ItFs rare that some one will as ste' * ste' all the alidation !ontrols#&am'le in
one o" the interiews i was ased how do *ou dis'la* summar* o" all errors in the
alidation !ontrol###So there goes the last one#
8/13/2019 dotnet faqs1
54/124
(B) Can *ou e'lain what is 9$utoEostBa! "eature in
$SE#%&T ?
I" we want the !ontrol to automati!all* 'osta! in !ase o" an* eent , we will need to
!he! this attriute as true#&am'le on a ComoBo !hange we need to send the eent
immediatel* to the serer side then set the 9$utoEostBa! attriute to true#
(B) ow !an *ou enale automati! 'aging in 2ata5rid ?
ollowing are the 'oints to e done in order to enale 'aging in 2atagrid :-
4 Set the 9$llowEaging to true#
4 In EageIndeChanged eent set the !urrent 'ageinde !li!ed#
%ote:- The answers are er* short , i" *ou hae im'lemented 'ra!ti!all* its 6ust a
reision#I" *ou are "resher 6ust mae sam'le !ode using 2atagrid and tr* to im'lement this
"un!tionalit*#
(B) What8s the use o" 95L
8/13/2019 dotnet faqs1
55/124
is 'ro!ess where we !he! does this identit* hae a!!ess rights to the s*stem# In short we
!an sa* the "ollowing authenti!ation is the 'ro!ess o" otaining some sort o" !redentials
"rom the users and using those !redentials to eri"* the user8s identit*# $uthori7ation is
the 'ro!ess o" allowing an authenti!ated user a!!ess to resour!es# $uthenti!ation is alwa*s
're!edes to $uthori7ation een i" *our a''li!ation lets anon*mous users !onne!t and
use the a''li!ation, it still authenti!ates them as eing anon*mous#
>>
(I) What is im'ersonation in $SE#%&T ?
B* de"ault, $SE#%&T ee!utes in the se!urit* !ontet o" a restri!ted user a!!ount on the
lo!al ma!hine# Sometimes *ou need to a!!ess networ resour!es su!h as a "ile on a shared
drie, whi!h re=uires additional 'ermissions#
8/13/2019 dotnet faqs1
56/124
4 authenti!ation modeV'ass'ortU
4 authenti!ation modeV"ormsU
4 Custom authenti!ation where *ou might install an IS$EI "ilter in IIS that
!om'ares in!oming re=uests to list o" sour!e IE addresses, and !onsiders
re=uests to e authenti!ated i" the* !ome "rom an a!!e'tale address# In that
!ase, *ou would set the authenti!ation mode to none to 'reent an* o" the
#net authenti!ation 'roiders "rom eing triggered#
Windows authenti!ation and IIS
I" *ou sele!t windows authenti!ation "or *our $SE#%&T a''li!ation, *ou also hae to
!on"igure authenti!ation within IIS# This is e!ause IIS 'roides Windows authenti!ation#
IIS gies *ou a !hoi!e "or "our di""erent authenti!ation methods:
$non*mous, asi! digest and windows integrated
I" *ou sele!t anon*mous authenti!ation, IIS doesn8t 'er"orm an* authenti!ation, $n* one
is allowed to a!!ess the $SE#%&T a''li!ation#
I" *ou sele!t asi! authenti!ation, users must 'roide a windows username and 'assword
to !onne!t# ow eer this in"ormation is sent oer the networ in !lear tet, whi!h maesasi! authenti!ation er* mu!h inse!ure oer the internet#
I" *ou sele!t digest authenti!ation, users must still 'roide a windows user name and
'assword to !onne!t# oweer the 'assword is hashed e"ore it is sent a!ross the networ#
2igest authenti!ation re=uires that all users e running Internet &'lorer or later and
that windows a!!ounts to stored in a!tie dire!tor*#
I" *ou sele!t windows integrated authenti!ation, 'asswords neer !ross the networ#
Gsers must still hae a username and 'assword, ut the a''li!ation uses either the ereros
>A
or !hallengeOres'onse 'roto!ols authenti!ate the user# Windows-integrated authenti!ation
re=uires that all users e running internet e'lorer A#1> or later ereros is a networauthenti!ation 'roto!ol# It is designed to 'roide strong authenti!ation "or !lientOserer
a''li!ations * using se!ret-e* !r*'togra'h*# ereros is a solution to networ se!urit*
'rolems# It 'roides the tools o" authenti!ation and strong !r*'togra'h* oer the networ
to hel' to se!ure in"ormation in s*stems a!ross entire enter'rise
Eass'ort authenti!ation
Eass'ort authenti!ation lets *ou to use Mi!roso"t8s 'ass'ort seri!e to authenti!ate users
o" *our a''li!ation# I" *our users hae signed u' with 'ass'ort, and *ou !on"igure the
authenti!ation mode o" the a''li!ation to the 'ass'ort authenti!ation, all authenti!ation
duties are o""-loaded to the 'ass'ort serers#
Eass'ort uses an en!r*'ted !ooie me!hanism to indi!ate authenti!ated users# I" users
hae alread* signed into 'ass'ort when the* isit *our site, the*8ll e !onsidered
authenti!ated * $SE#%&T#
8/13/2019 dotnet faqs1
57/124
orms authenti!ation
orms authenti!ation 'roides *ou with a wa* to handle authenti!ation using *our own
!ustom logi! with in an $SE#%&T a''li!ation# The "ollowing a''lies i" *ou !hoose "orms
authenti!ation#
4 When a user re=uests a 'age "or the a''li!ation, $SE#%&T !he!s "or the
'resen!e o" a s'e!ial session !ooie# I" the !ooie is 'resent, $SE#%&T assumes
the user is authenti!ated and 'ro!esses the re=uest#
4 I" the !ooie isn8t 'resent, $SE#%&T redire!ts the user to a we "orm *ou
'roide
>0
Kou !an !arr* out whateer authenti!ation, !he!s *ou lie in *our "orm# When the user
is authenti!ated, *ou indi!ate this to $SE#%&T * setting a 'ro'ert*, whi!h !reates the
s'e!ial !ooie to handle suse=uent re=uests#
($)ow does authori7ation wor in $SE#%&T?
$SE#%&T im'ersonation is !ontrolled * entries in the a''li!ations we#!on"ig "ile# The
de"ault setting is 9no im'ersonation# Kou !an e'li!itl* s'e!i"* that $SE#%&T shouldn8tuse im'ersonation * in!luding the "ollowing !ode in the "ile
identit* im'ersonateV"alseOU
It means that $SE#%&T will not 'er"orm an* authenti!ation and runs with its own
'riileges# B* de"ault $SE#%&T runs as an un'riileged a!!ount named $SE%&T# Kou
!an !hange this * maing a setting in the 'ro!essModel se!tion o" the ma!hine#!on"ig
"ile# When *ou mae this setting, it automati!all* a''lies to eer* site on the serer# To
user a high-'riileged s*stem a!!ount instead o" a low-'riileged, set the user%ame
attriute o" the 'ro!essModel element to SKST&M# Gsing this setting is a de"inite se!urit*
ris, as it eleates the 'riileges o" the $SE#%&T 'ro!ess to a 'oint where it !an do ad
things to the o'erating s*stem#When *ou disale im'ersonation, all the re=uest will run in the !ontet o" the a!!ount
running $SE#%&T: either the $SE%&T a!!ount or the s*stem a!!ount# This is true when
*ou are using anon*mous a!!ess or authenti!ating users in some "ashion# $"ter the user
has een authenti!ated, $SE#%&T uses it own identit* to re=uest a!!ess to resour!es#
The se!ond 'ossile setting is to turn on im'ersonation#
identit* im'ersonate VtrueOU
In this !ase, $SE#%&T taes on the identit* IIS 'asses to it# I" *ou are allowing anon*mous
a!!ess in IIS, this means $SE#%&T will im'ersonate the IGS+QCom'uter%ame a!!ount
that IIS itsel" uses# I" *ou aren8t allowing anon*mous a!!ess,$SE#%&T will tae on the
!redentials o" the authenti!ated user and mae re=uests "or resour!es as i" it were that
user# Thus * turning im'ersonation on and using a non-anon*mous method o"
authenti!ation in IIS, *ou !an let users log on and use their identities within *our $SE#%&T
a''li!ation#
inall*, *ou !an s'e!i"* a 'arti!ular identit* to use "or all authenti!ated re=uests
identit* im'ersonateVtrue usernameV2
8/13/2019 dotnet faqs1
58/124
With this setting, all the re=uests are made as the s'e!i"ied user ($ssuming the 'assword
it !orre!t in the !on"iguration "ile)# So, "or eam'le *ou !ould designate a user "or a single
a''li!ation, and use that user8s identit* eer* time someone authenti!ates to the
a''li!ation# The drawa! to this te!hni=ue is that *ou must emed the user8s 'assword
in the we#!on"ig "ile in 'lain tet# $lthough $SE#%&T won8t allow an*one to download
this "ile, this is still a se!urit* ris i" an*one !an get the "ile * other means#
(B)What8s di""eren!e etween 2atagrid , 2atalist and
re'eater ?
$ 2atagrid, 2atalist and +e'eater are all $SE#%&T data We !ontrols#
The* hae man* things in !ommon lie 2ataSour!e Ero'ert* , 2ataBind Method
Item2ataBound and ItemCreated#
When *ou assign the 2ataSour!e Ero'ert* o" a 2atagrid to a 2ataSet then ea!h 2ata+ow
'resent in the 2ata+ow Colle!tion o" 2ataTale is assigned to a !orres'onding
2ata5ridItem and this is same "or the rest o" the two !ontrols also#But The TML !ode
generated "or a 2atagrid has an TML T$BL& +
8/13/2019 dotnet faqs1
59/124
2ata5rid and 2ataList# B* re=uiring the deelo'er to s'e!i"* the !om'lete generated
TML maru', the +e'eater o"ten re=uires the longest deelo'ment time#But re'eater
does not 'roide editing "eatures lie datagrid so eer*thing has to e !oded * 'rogrammer
# oweer, the +e'eater does oast the est 'er"orman!e o" the three data We !ontrols#
+e'eater is "astest "ollowed * 2atalist and "inall* datagrid#
(B) 2i""eren!e etween $SE and $SE#%&T?
$SE#%&T new "eature su''orts are as "ollows :-
Better Language Su''ort
4 %ew $2
8/13/2019 dotnet faqs1
60/124
new re=uests to the new !ode#
($) What are ma6or eents in 5L
8/13/2019 dotnet faqs1
61/124
SessionQ&nd: ired when a userFs session times out, ends, or the* leae the a''li!ation
We site#
%ote :- 2uring interiew *ou do not hae to reall* !ram all these eents#But 6ust ee' the
asi! eents in mind
($) What order the* are triggered ?
The*Fre triggered in the "ollowing order:
$''li!ationQBegin+e=uest
$''li!ationQ$uthenti!ate+e=uest
$''li!ationQ$uthori7e+e=uest
$''li!ationQ+esole+e=uestCa!he
$''li!ationQ$!=uire+e=uestState
$''li!ationQEre+e=uestandler&e!ute
>A1
$''li!ationQEreSend+e=uesteaders
$''li!ationQEreSend+e=uestContent
!ode is ee!utedUU$''li!ationQEost+e=uestandler&e!ute
$''li!ationQ+elease+e=uestState
$''li!ationQG'date+e=uestCa!he
$''li!ationQ&nd+e=uest#
(I) 2o session use !ooies ?
Twist:- ow !an we mae session to not to use !ooies ?
Le"t to the user , *ou will en6o* to "ind this answer#
(I)ow !an we "or!e all the alidation !ontrol to run ?
Eage#.alidate
(B)ow !an we !he! i" all the alidation !ontrol are alidand 'ro'er ?
Gsing the Eage#Is.alid() 'ro'ert* *ou !an !he! whether all the alidation are done#
($)I" *ou hae !lient side alidation is enaled in *our We
'age , 2oes that mean serer side !ode is not run?
When !lient side alidation is enaled serer emit8s JaaS!ri't !ode "or the !ustom
alidators# But note that does not mean that serer side !he!s on !ustom alidators do
not ee!ute# It does this two time redundant !he!# $s some o" the alidators do not
su''ort !lient side s!ri'ting#
($)Whi!h JaaS!ri't "ile is re"eren!ed "or alidating the
alidators at the !lient side ?
>A>
WeGI.alidation#6s 6aas!ri't "ile installed at 9as'netQ!lient root IIS dire!tor* is used
to alidate the alidation !ontrols at the !lient side
(B)ow to disale !lient side s!ri't in alidators?
Set &naleClientS!ri't to "alse#
($)I want to show the entire alidation error message in a
message o on the !lient side?
8/13/2019 dotnet faqs1
62/124
In alidation summar* set 9ShowMessageBo to true#
(B)Kou "ind that one o" *our alidation is er* !om'li!ated
and does not "it in an* o" the alidators , so what will *ou do
?
Best is to go "or Custom.alidators##Below is a sam'le !ode "or a !ustom alidator whi!h
!he!s that a teto should not hae 7ero alue
as':Custom.alidator idVHCustom.alidator>H runatVHsererH
&rrorMessageVH%umer not diisile * ceroH
ControlTo.alidateVHtt%umerH
8/13/2019 dotnet faqs1
63/124
4 #as', "or $SE#%&T We 'ages,
4 #asm, "or $SE#%&T We seri!es,
4 #!on"ig, "or $SE#%&T !on"iguration "iles,
>AA
4 #ash, "or !ustom $SE#%&T TTE handlers,
4 #rem, "or remoting resour!es
4 &t!
Kou !an also !on"igure the etension ma''ing to whi!h engine it !an route * using the
IIS engine#
igure: - #> ollowing s!reen shows some IIS ma''ings
>A0
&am'le a $SE 'age will e sent to old !lassi! $SE#2LL to !om'ile# While #$SE 'ages
will e routed to $SE#%&T engine "or !om'ilation#
4 $s this oo mainl* will target $SE#%&T we will loo in to how $SE#%&T
'ages that is $SE 'ages generation se=uen!e o!!urs# #1#111#1,
CultureVneutral, Euli!e*ToenV1A""">>d1aAaH O
U
Ohtt'ModulesU
>A
The aoe ma''ing shows whi!h "un!tionalit* is handled * whi!h %ames'a!e# &am'le
orms$thuenti!ation is handled * 9S*stem#We#Se!urit*#orms$uthenti!ationModule#
8/13/2019 dotnet faqs1
64/124
I" *ou loo at the we#!on"ig se!tion TTE module is where authenti!ation and
authori7ation ha''ens#
8/13/2019 dotnet faqs1
65/124
elow "igure there are "ie 'ro!esses and eer* one handling indiidual a''li!ation# This
!onsumes hea* memor* ut has highest reliailit*#
>AD
igure: - # igh isolation s!enario
($)$SE used ST$ threading model , whats the threading
model used "or $SE#%&T ?
$SE#%&T uses MT$ threading model#
($)Whats the use o" _` 'age as'!om'atVtrue _U
attriute ?
This attriute wors lie a !om'atiilit* o'tion# $s said e"ore $SE wored in STS model
and $SE#%&T wors in MT$ model# But what i" *our $SE#%&T a''li!ation is using a
.B C01(B)&'lain the di""eren!es etween Serer-side and Clientside
!ode?
Serer side !ode is ee!uted at the serer side on IIS in $SE#%&T "ramewor , while
!lient side !ode is ee!uted on the rowser#
(I)Can *ou e'lain orms authenti!ation in detail ?
In old $SE i" *ou where said to !reate a login 'age and do authenti!ation *ou hae to do
hell lot o" !ustom !oding# But now in $SE#%&T that8s made eas* * introdu!ing orms
authenti!ation# So let8s see in detail what "orm authenti!ation is#
orms authenti!ation uses a ti!et !ooie to see that user is authenti!ated or not# That
means when user is authenti!ated "irst time a !ooie is set to tell that this user isauthenti!ated# I" the !ooies e'ire then orms authenti!ation me!hanism sends the user
to the login 'age#
ollowing are the ste's whi!h de"ines ste's "or orms authenti!ation :-
4 Con"igure We#!on"ig "ile with "orms authenti!ation#$s shown elow in the
!on"ig "ile *ou !an see we hae gie the !ooie name and loginurl 'age#
!on"igurationU
s*stem#weU
]--
8/13/2019 dotnet faqs1
66/124
>0>
4 +emoe anon*mous a!!ess to the IIS we a''li!ation , "ollowing are !hanges
done to we#!on"ig "ile#
!on"igurationU
s*stem#weU
]-- H runatVHsererH $utoEostBa!VHTrueH
8/13/2019 dotnet faqs1
67/124
9'rote!ted or 9'uli!
4 ollowing elow is the suroutine whi!h de"ines the method
Erote!ted Su Che!QCli!ed(B*.al sender $s 00
4 Kou !an oerride the "ollowing eents 'roided * seri!e and write *our
!ustom !ode# $ll the three main eents !an e used that is Start , sto' and
!ontinue#
'rote!ted oerride oid
8/13/2019 dotnet faqs1
68/124
Creational Eatterns
4 $stra!t a!tor*:- Creates an instan!e o" seeral "amilies o" !lasses
4 Builder :- Se'arates o6e!t !onstru!tion "rom its re'resentation
4 a!tor* Method:- Creates an instan!e o" seeral deried !lasses
4 Erotot*'e:- $ "ull* initiali7ed instan!e to e !o'ied or !loned
4 Singleton:- $ !lass o" whi!h onl* a single instan!e !an eist
%ote :- The est wa* to rememer Creational 'attern is * $BES ($raham Be!ame
irst Eresident o" States)#
Stru!tural Eatterns
4 $da'ter:-Mat!h inter"a!es o" di""erent !lasses#
4 Bridge:-Se'arates an o6e!t8s inter"a!e "rom its im'lementation#
4 Com'osite:-$ tree stru!ture o" sim'le and !om'osite o6e!ts#
4 2e!orator :-$dd res'onsiilities to o6e!ts d*nami!all*#
4 aade:-$ single !lass that re'resents an entire sus*stem#
4 l*weight:-$ "ine-grained instan!e used "or e""i!ient sharing#
4 Ero*:-$n o6e!t re'resenting another o6e!t#@##%&T $r!hite!ture
>03
%ote : To rememer stru!tural 'attern est is ($BC2E)
Behaioral Eatterns
4 Mediator:-2e"ines sim'li"ied !ommuni!ation etween !lasses#
4 Memento:-Ca'ture and restore an o6e!tFs internal state#
4 Inter'reter:-$ wa* to in!lude language elements in a 'rogram#
4 Iterator:-Se=uentiall* a!!ess the elements o" a !olle!tion#
4 Chain o" +es':-$ wa* o" 'assing a re=uest etween a !hain o" o6e!ts#
4 Command:-&n!a'sulate a !ommand re=uest as an o6e!t#4 State:-$lter an o6e!tFs ehaior when its state !hanges#
4 Strateg*:-&n!a'sulates an algorithm inside a !lass#
4
8/13/2019 dotnet faqs1
69/124
method to !om'lete the ar!hite!ture# $stra!t a!tor* is one leel higher in astra!tion
oer a!tor*#
>0
The elow two !lass diagrams will 'roide oeriew o" what the a!tual di""eren!e is#
irst "igure shows a sam'le im'lementation o" a!tor* Eatterns# In this "igure there are
two asi! se!tions:-
4 The a!tual 'rodu!t se!tion i#e# Class 9Erodu!t it inherits "rom a astra!t
!lass 9$stra!tErodu!t#
4 The !reational as'e!t se!tion that8s 9Con!reteCreator !lass whi!h inherits
"rom !lass 9Creator#
4 %ow there are some rules the !lient who will need the 9Erodu!t o6e!t will
"ollow# e will neer re"er dire!tl* to the a!tual 9Erodu!t o6e!t he will re"er
the 9Erodu!t o6e!t using 9$stra!tErodu!t#
4 Se!ond !lient will neer use 9%ew e*word to !reate the 9Erodu!t o6e!t
ut will use the 9Creator !lass whi!h in turn will use the 9Con!reteCreator
!lass to !reate the a!tual 9Erodu!t o6e!t#igure: - @#> Class diagram o" a "a!tor* Eattern
So what are ene"its "rom this ar!hite!ture? $ll !reational and initiali7ing as'e!ts are
now deta!hed "rom the a!tual !lient# $s *our !reational as'e!t is now een handled in
9Con!reteCreator and the !lient has re"eren!e to onl* 9Creator, so an* im'lementation
!hange in 9CreateErodu!t will not a""e!t the !lient !ode# In short now *ou !reational
as'e!t o" o6e!t is !om'letel* en!a'sulated "rom the !lient8s logi!#
%ow let8s loo at the se!ond !lass diagram whi!h 'roides an oeriew o" what a!tuall*
9$stra!t "a!tor* 'attern is# It !reates o6e!ts "or "amilies o" !lasses# In short it des!ries
!olle!tion o" "a!tor methods "rom arious di""erent "amilies# In short it grou's related
>0@"a!tor* methods# &am'le in this the !lass 9Creator is im'lemented using the 9$stra!t
"a!tor* 'attern# It now !reates o6e!ts "rom multi'le "amilies rather one 'rodu!t#
%ote :- Just sti! u' to this de"inition that $stra!t "a!tor* !lassi"ies "a!tor* methods or
grou's logi!all* related "a!tor* method together##
igure:- @# Class 2iagram o" $stra!t a!tor*
>0D
(I)What8s M.C 'attern?
Twist: - ow !an *ou im'lement M.C 'attern in $SE#%&T?
The main 'ur'ose using M.C 'attern is to de!ou'le the 5GI "rom the 2ata# It also gies
the ailit* to 'roide multi'le iews "or the same 2ata# M.C 'attern se'arates o6e!ts in
to three im'ortant se!tions:-
4 Model: - This se!tion is s'e!iall* "or maintaining data# It is a!tuall* where *our
usiness logi!, =uer*ing dataase, dataase !onne!tion et!# is a!tuall*
im'lemented#
4 .iews: - 2is'la*ing all or some 'ortion o" data, or 'roal* di""erent iew o"
data# .iew is res'onsile "or loo and "eel, Sorting, "ormatting et!#
4 Controller: - The* are eent handling se!tion whi!h a""e!ts either the model or
8/13/2019 dotnet faqs1
70/124
the iew# Controller res'onds to the mouse or e*oard in'ut to !ommand
model and iew to !hange# Controllers are asso!iated with iews# Gser
intera!tion triggers the eents to !hange the model, whi!h in turn !alls some
methods o" model to u'date its state to noti"* other registered iews to re"resh
their dis'la*#
8/13/2019 dotnet faqs1
71/124
a!tuall* does !hange on the main o6e!t itsel"# So how is dee' !o'* a!hieed, * using
9ISeriali7ale inter"a!e? So what *ou do is "irst seriali7e the o6e!t then deseriali7e a!
to a !om'lete new !o'*# %ow an* !hanges to this new !o'* do not re"le!t on the original
!o'* o" the o6e!t, this is !alled as 2ee' !o'*#
(I)What are the situations *ou will use a We Seri!e and +emoting in
'ro6e!ts?
Well 9We seri!es uses 9remoting !on!e'ts internall*# But the ma6or di""eren!e etween
9we seri!e and 9remoting is that 9we seri!e !an e !onsumed * !lients who are
not #%&T 'lat"orm# While remoting *ou need the !lient to e #%&T !om'liant# +egarding
the s'eed issue 9+emoting is "aster than 9We Seri!es# So I thin when de!iding the
ar!hite!ture side o" !hoosing etween 9We seri!es and 9+emoting ee' the !ross
'lat"orm issue and the s'eed issue in mind#
($)Can *ou gie a 'ra!ti!al im'lementation o" $f$2& 'atterns?
>
aade 'attern sits on the to' o" lot o" sus*stems and maes a!!ess eas* to inter"a!es
o" these sus*stems# Basi! 'ur'ose o" aade is to mae inter"a!ing etween man*modules and !lasses manageale#
igure: - @#0 aade in a!tion
$oe is a sim'le lie a''li!ation o" a aade !lass# In this we hae "our sus*stems :-
4 Customer
4 Erodu!t
>A
4 Ea*ment
4 Inoi!ing
$ll the "our modules when uilt at initial stage where uilt !om'letel* inde'endent# The
main intera!tion etween all these sus*stems is !ustomer 'la!ing order# This "un!tionalit*!an e attained * using all these sus*stems, whi!h inoles !om'le intera!tion etween
them#
There8s where $f$2& !omes in to a!tion# We hae uilt a $f$2& !alled as
9$C$2&
8/13/2019 dotnet faqs1
72/124
and dataase staging#
2ata $!!ess La*er: - This is also !alled * the "amous a!ron*m H2$LH !om'onent# It has
mainl* the S\L statement whi!h do the dataase o'eration 'art o" the 6o#
The three tier ar!hite!ture is used when an e""e!tie distriuted !lientOserer design is
needed that 'roides (when !om'ared to the two tier) in!reased 'er"orman!e, "leiilit*,
maintainailit*, reusailit*, and s!alailit*, while hiding the !om'leit* o" distriuted
'ro!essing "rom the user#
>0
(I)ae *ou eer wored with Mi!roso"t $''li!ation Blo!s, i" *es then
whi!h?
$''li!ation Blo!s are CN and .B#%&T !lasses distriuted as .isual Studio 'ro6e!ts
that !an e downloaded "rom Mi!roso"tFs We site and used in an* #%&T a''li!ation,
in!luding $SE#%&T We a''li!ations# The* are use"ul and 'ower"ul tools that !an mae
a''li!ations more maintainale, s!alale and e""i!ient
The se!ond =uestion whi!h o" the a''li!ation lo!s has een used de'ends on reall*
what *ou hae im'lemented# But there are two "amous M$B whi!h is maing u77 aroundthe industr*:-
4 data a!!ess lo!
The 2ata $!!ess Blo! 'roides stati! methods lo!ated in the S=lel'er !lass
that en!a'sulates the most !ommon data a!!ess tass 'er"ormed with Mi!roso"t
S\L serer# I" the term Hstati! methodH is new to *ou, it means that the !lass
methods !an e !alled without instantiating an instan!e o" the !lass# or
eam'le, the method &e!ute+eader () within the S=lel'er !lass !an e !alled
* sim'l* using the statement S=lel'er#&e!ute+eader () -- no o6e!t
instantiation o" the S=lel'er !lass is re=uired#
4 &!e'tion management lo!#The &!e'tion Management $''li!ation Blo! 'roides a sim'le *et etensile
"ramewor "or handling e!e'tions# With a single line o" a''li!ation !ode *ou
!an easil* log e!e'tion in"ormation to the &ent Log or etend it * !reating
*our own !om'onents that log e!e'tion details to other data sour!es or noti"*
o'erators, without a""e!ting *our a''li!ation !ode# The &!e'tion Management
$''li!ation Blo! !an easil* e used as a uilding lo! in *our own #%&T
a''li!ation
%ote: - It8s e*ond the s!o'e the oo to loo in to details o" a''li!ation lo!# Best is go to
www#mi!roso"t#!om and sear!h "or these a''li!ation lo!# Tr* to !om'ile one or two
'rograms using there gien !lasses and do!umentation#
($)What is Seri!e
inter"a!es o" these !om'onents# S
8/13/2019 dotnet faqs1
73/124
!rossing oundaries# Kou !an loo S3
igure: - @# S
8/13/2019 dotnet faqs1
74/124
The Windows 2istriuted inter%et $''li!ations $r!hite!ture (2%$) is a Mi!roso"t
lue'rint "or roust, s!alale, distriuted usiness so"tware# Windows 2%$ has eoled
oer time and was not 're'lanned# It gies all !omined adantages o" Centrali7ed
main"rame, a''li!ation serers, internet te!hnologies and Eersonal !om'uters# Windows
2%$ is a eolution whi!h started "rom main"rames (Where all logi! was !entrali7ed) ,
o 'ro ages ( Where we taled in terms o" two tier s*stems) , .B3 O S\L S&+.&+
(Three tier where we taled in terms o" haing one more tier whi!h was mainl* C@
where usiness logi! resided) , C
8/13/2019 dotnet faqs1
75/124
9$ !on!ern is a 'arti!ular goal, !on!e't, or area o" interest
There are mainl* two t*'es o" !on!ern "rom an o6e!t 'ers'e!tie:-
4 Core O Main !on!erns whi!h it should satis"* and is his wor#
I ho'e in m* se!ond edition i will !ome out with a se'erate !ha'ter on $31
4 S*stem !on!erns whi!h are not related to usiness "un!tionalities ut so"tware
related !on!erns eam'le audit trail, &rror handling, Se!urit* et!#
1 length (Business leel
!on!ern)
4 $ll !ustomer data whi!h is u'dated should e audited# (S*stem leel !on!ern)ere goes the !lass !ode# I" *ou see the ClsCustomer im'lementation in the u'date method
I hae !alled the $udit trail im'lementation# I" *ou reall* loo "rom o6e!t oriented 'oint
o" iew we are doing something in !ustomer !lass whi!h is su''osed to e not his
im'lementation: - $udit Trail logging# Thus we hae also roen down the rule o"
>3>
en!a'sulation# In short the !lass not onl* handles his wor ut also some other wor
whi!h is not his !on!ern#
8/13/2019 dotnet faqs1
76/124
5et
+eturn 'strCust%ame
&nd 5et
Set(B*.al .alue $s String)
>3
'strCust%ame V .alue
&nd Set
&nd Ero'ert*
Euli! un!tion G'date() $s Boolean
X "irst O !ore !on!ern
I" 'strCust!ode#Length() U >1 Then
Throw %ew &!e'tion(H.alue !an not e greater than >1H)
&nd I"
F usingthe !ustomer audit trail to do auditing
X se!ond !on!ern O s*stem !on!ern
2im 'o6Cls$uditTrail $s %ew Cls$uditTrailWith 'o6Cls$uditTrail
#%ew.alue V H>11>H
#11AH
#Gser%ame V HshiH
#G'date()
&nd With
F then inserting the !ustomer in dataase
&nd un!tion
&nd Class
Euli! Class Cls$uditTrailEriate 'strGser%ame $s String
Eriate 'str3A
Euli! Ero'ert* Gser%ame() $s String
5et
+eturn 'strGser%ame
&nd 5et
Set(B*.al .alue $s String)
'strGser%ame V .alue
&nd Set
&nd Ero'ert*
Euli! Ero'ert*
8/13/2019 dotnet faqs1
77/124
Set(B*.al .alue $s String)
'str30
5et
+eturn 'dlLogTime&nd 5et
Set(B*.al .alue $s 2oule)
'dlLogTime V .alue
&nd Set
&nd Ero'ert*
Euli! Su G'date()
F do the logging a!tiit* here
&nd Su
&nd Class
In short the !ustomer !lass is doing lot o" a!tiit*# There is lot o" tangling o" !ode# Sohow do we oer!ome this 'rolem Sim'le se'arate the S*stem leel !on!ern ($udit
Trail) "rom the !ore leel !on!ern ( Customer !ode !he!)# This is a!hieed at this
moment in #%&T using attriute 'rogramming#
ere is the !hange to the !ustomer !lass
Im'orts S*stem#+e"le!tion
Euli! Class ClsCustomer
Eriate 'strCust!ode $s String
Eriate 'strCust%ame $s String
Euli! Ero'ert* Code() $s String
5et
+eturn 'strCust!ode
&nd 5et
Set(B*.al .alue $s String)
>3
'strCust!ode V .alue
&nd Set
&nd Ero'ert*
8/13/2019 dotnet faqs1
78/124
Euli! Ero'ert* Customer%ame() $s String
5et
+eturn 'strCust%ame
&nd 5et
Set(B*.al .alue $s String)
'strCust%ame V .alue
&nd Set
&nd Ero'ert*
Cls$uditTrail(HShiH, H>11>H, H>11AH, >)U Q
Euli! un!tion G'date() $s Boolean
I" 'strCust!ode#Length() U >1 Then
Throw %ew &!e'tion(H.alue !an not e greater than >1H)
&nd I"
F usingthe !ustomer audit trail to do auditing
F then inserting the !ustomer in dataase
&nd un!tion&nd Class
>33
$nd here is the !hange to the audit trail !lass
Im'orts S*stem#+e"le!tion
$ttriuteGsage($ttriuteTargets#$ll)U Q
Euli! Class Cls$uditTrail
Inherits $ttriute
Eriate 'strGser%ame $s String
Eriate 'str
8/13/2019 dotnet faqs1
79/124
&nd Ero'ert*
Euli! Ero'ert* %ew.alue() $s String
5et
+eturn 'str%ew.alue
&nd 5et
Set(B*.al .alue $s String)
'str%ew.alue V .alue
&nd Set
&nd Ero'ert*
Euli! Ero'ert* LogTime() $s 2oule
5et
+eturn 'dlLogTime
&nd 5et
Set(B*.al .alue $s 2oule)
'dlLogTime V .alue
&nd Set&nd Ero'ert*
Euli! Su %ew(B*.al 'strGser%ame $s String, Q
B*.al 'str3@&nd Su
&nd Class
The "un 'art o" the !ode is elow , *ou !an see that the !ode audit trail is now se'erate
and the !ode !he! elongs to the !ustomer !ode#
Cls$uditTrail(HShiH, H>11>H, H>11AH, >)U Q
Euli! un!tion G'date() $s Boolean
I" 'strCust!ode#Length() U >1 Then
Throw %ew &!e'tion(H.alue !an not e greater than >1H)
&nd I"
F usingthe !ustomer audit trail to do auditing
F then inserting the !ustomer in dataase
&nd un!tion
%ote:- $r!hite!ture is eer*od*s "aorite and the wide !omination is di""i!ult to e !oered
in this oo# Man* o" the things !an onl* !ome * lie e'erien!e#
$2
8/13/2019 dotnet faqs1
80/124
(B)What is the names'a!e in whi!h #%&T has the data
"un!tionalit* !lasses ?
ollowing are the names'a!es 'roided * #%&T "or data management :-
S*stem#data
This !ontains the asi! o6e!ts used "or a!!essing and storing relational data, su!h as
2ataSet,2ataTale, and 2ata+elation# &a!h o" these
Recommended