C Sharp DotNet interview questions.docx
《C Sharp DotNet interview questions.docx》由会员分享,可在线阅读,更多相关《C Sharp DotNet interview questions.docx(123页珍藏版)》请在冰豆网上搜索。
CSharpDotNetinterviewquestions
ASP.NET
Whatisviewstateanduseofit?
ThecurrentpropertysettingsofanASP.NETpageandthoseofanyASP.NETservercontrolscontainedwithinthepage.ASP.NETcandetectwhenaformisrequestedforthefirsttimeversuswhentheformisposted(senttotheserver),which allowsyoutoprogramaccordingly.
Whatareusercontrolsandcustomcontrols?
Customcontrols:
Acontrolauthoredbyauserorathird-partysoftwarevendorthatdoesnotbelongto the.NETFrameworkclasslibrary.Thisisagenerictermthatincludesusercontrols.A customservercontrolisusedinWebForms(ASP.NETpages).Acustomclientcontrolisused inWindowsFormsapplications.
UserControls:
InASP.NET:
Auser-authoredservercontrolthatenablesanASP.NETpagetobere-used asaservercontrol.AnASP.NETusercontrolisauthoreddeclaratively andpersistedasa textfilewithan.ascxextension.TheASP.NETpageframeworkcompilesausercontrolon theflytoaclassthatderivesfromthe System.Web.UI.UserControlclass.
Whatarethevalidationcontrols?
AsetofservercontrolsincludedwithASP.NETthattestuserinputinHTMLandWebserver controlsforprogrammer-definedrequirements.Validationcontrolsperforminputcheckingin servercode.IftheuserisworkingwithabrowserthatsupportsDHTML,thevalidation controlscanalsoperformvalidationusingclientscript.
What'sthedifferencebetweenResponse.Write()andResponse.Output.Write()?
Thelatteroneallowsyoutowriteformattedoutput.
Whatmethodsarefiredduringthepageload?
Init()
Whenthepageisinstantiated,Load()-whenthepageisloadedintoserver memory,PreRender ()-thebriefmomentbeforethepageisdisplayedtotheuser asHTML, Unload()- whenpagefinishesloading.
WheredoestheWebpagebelonginthe.NETFrameworkclasshierarchy?
System.Web.UI.Page
Wheredoyoustoretheinformationabouttheuser'slocale?
System.Web.UI.Page.Culture
What'sthedifferencebetweenCodebehind="MyCode.aspx.cs"andSrc="MyCode.aspx.cs"?
CodeBehindisrelevanttoVisualStudio.NETonly.
What'sabubbledevent?
Whenyouhaveacomplexcontrol,likeDataGrid,writinganeventprocessingroutineforeach object(cell,button,row,etc.)isquitetedious.Thecontrolscanbubbleuptheir eventhandlers,allowingthemainDataGrideventhandlertotakecareofitsconstituents.
SupposeyouwantacertainASP.NETfunctionexecutedonMouseOveroveracertainbutton.
Wheredoyouaddaneventhandler?
It'stheAttributesproperty,theAddfunctioninsidethatproperty.
e.g.btnSubmit.Attributes.Add("onMouseOver","someClientCode();")
WhatdatatypedoestheRangeValidatorcontrolsupport?
Integer,StringandDate.
Whatarethedifferenttypesofcaching?
Cachingisatechniquewidelyusedincomputingtoincreaseperformancebykeeping frequentlyaccessedorexpensivedatainmemory.Incontextofwebapplication,cachingis usedtoretainthepagesordataacrossHTTPrequestsandreusethemwithouttheexpenseof recreatingthem.ASP.NEThas3kindsofcachingstrategiesOutputCachingFragmentCachingData
CachingOutputCaching:
Cachesthedynamicoutputgeneratedbyarequest.Sometimesitis usefultocache theoutputofawebsiteevenforaminute,whichwillresultinabetter performance.ForcachingthewholepagethepageshouldhaveOutputCachedirective.<%@OutputCacheDuration="60"VaryByParam="state"%>
FragmentCaching:
Cachestheportionofthe pagegeneratedbytherequest.Sometimesitisnotpracticaltocachetheentirepage,in suchcaseswecancacheaportionofpage<%@OutputCacheDuration="120"VaryByParam="CategoryID;SelectedID"%>
DataCaching:
Cachestheobjectsprogrammatically.For datacachingprovidesacacheobjectforeg:
cache["States"]=dsStates;
Whatdoyoumeanbyauthenticationandauthorization?
Authenticationistheprocessofvalidatingauseronthecredentials(usernameand password)andauthorizationperformsafterauthentication.AfterAuthenticationauserwill beverifiedforperformingthevarioustasks,Itaccessislimiteditisknownas authorization.
Whataredifferenttypesofdirectivesin.NET?
@Page:
Definespage-specificattributesusedbytheASP.NETpageparserandcompiler.Can beincludedonlyin.aspxfiles <%@PageAspCompat="TRUE"language="C#"%>
@Control:
Definescontrol-specificattributesusedbytheASP.NETpageparserand compiler.Canbeincludedonlyin.ascxfiles.<%@ControlLanguage="VB"EnableViewState="false"%>
@Import:
Explicitlyimportsanamespaceintoapageorusercontrol.TheImport directivecannothavemorethanonenamespaceattribute.Toimportmultiple namespaces, usemultiple@Importdirectives.<%@ImportNamespace="System.web"%>
@Implements:
Indicatesthatthecurrentpageorusercontrolimplementsthespecified.NET frameworkinterface.<%@ImplementsInterface="System.Web.UI.IPostBackEventHandler"%>
@Register:
Associatesaliaseswithnamespacesandclassnamesforconcisenotationin customservercontrolsyntax.<%@RegisterTagprefix="Acme"Tagname="AdRotator"Src="AdRotator.ascx"%>
@Assembly:
Linksanassemblytothecurrentpageduringcompilation,makingall the assembly'sclassesandinterfacesavailableforuseonthe page.<%@AssemblyName="MyAssembly"%><%@AssemblySrc="MySource.vb"%>
@OutputCache:
DeclarativelycontrolstheoutputcachingpoliciesofanASP.NETpageora usercontrolcontainedinapage<%@OutputCacheDuration="#ofseconds"Location="Any|Client|Downstream|Server|None"Shared="True|False"VaryByControl="controlname"VaryByCustom="browser|customstring"VaryByHeader="headers"VaryByParam="parametername"%>
@Reference:
Declarativelyindicatesthatanotherusercontrolorpagesourcefile shouldbedynamicallycompiledandlinkedagainstthepageinwhichthisdirectiveis declared.
HowdoIdebuganASP.NETapplicationthatwasn'twrittenwithVisualStudio.NETandthatdoesn'tusecode-behind?
StarttheDbgClrdebuggerthatcomeswiththe.NETFrameworkSDK,openthefilecontaining thecodeyouwanttodebug,andsetyourbreakpoints.StarttheASP.NETapplication.Go backtoDbgClr,chooseDebugProcessesfromtheToolsmenu,andselect aspnet_wp.exefrom thelistofprocesses.(Ifaspnet_wp.exedoesn'tappearinthelist,checkthe"Showsystem processes"box.)ClicktheAttachbuttontoattachtoaspnet_wp.exeandbegin debugging.
BesuretoenabledebuggingintheASPXfilebeforedebuggingitwithDbgClr.Youcan enabletellASP.NETtobuilddebugexecutablesbyplacinga
<%@PageDebug="true"%> statementatthetopofanASPXfileora statementinaWeb.configfile.
CanauserbrowsingmyWebsitereadmyWeb.configorGlobal.asaxfiles?
No.ThesectionofMachine.config,whichholdsthemasterconfiguration settingsforASP.NET,containsentriesthatmapASAXfiles,CONFIGfiles,andselected otherfiletypestoanHTTPhandlernamedHttpForbiddenHandler,whichfailsattemptsto retrievetheassociatedfile. Youcanmodifyitbyediting Machine.configorincludingansectioninalocalWeb.config file.
What'sthedifferencebetweenPage.RegisterClientScriptBlockandPage.RegisterStartupScript?
RegisterClientScriptBlockisforreturningblocksofclient-sidescriptcontaining functions.RegisterStartupScriptisforreturningblocksofclient-scriptnot packagedinfunctions-inotherwords,codethat'stoexecutewhenthepageisloaded. Thelatterpositionsscriptblocksneartheendofthedocumentsoelementsonthepage thatthescriptinteractsareloadedbeforethescriptruns.<%@ReferenceControl="MyControl.ascx"%>
Isitnecessarytolockapplicationstatebeforeaccessingit?
Onlyifyou'reperformingamultistepupdateandwanttheupdatetobetreatedasanatomic operation.Here'sanexample:
Application.Lock();
Application["ItemsSold"]=(int)Application["ItemsSold"]+1;
Application["ItemsLeft"]=(int)Application["ItemsLeft"]-1;
Application.UnLock();
Bylockingapplicationstatebeforeupdatingitandunlockingitafterwards,youensure thatanotherrequestbeingprocessedonanotherthreaddoesn'treadapplicationstate atexactlythewrongtimeandseeaninconsistentviewofit.IfIupdatesessionstate,shouldIlockit,too?
Areconcurrentaccessesbymultiplerequestsexecutingonmultiplethreadsaconcernwithsessionstate?
Concurrentaccessesaren'tanissuewithsessionstate,fortworeasons.One,it'sunlikelythattworequestsfromthesameuserwilloverlap.Two,iftheydooverlap,ASP.NETlocksdownsessionstateduringrequestprocessingsothattwothreadscan'ttouchitatonce.SessionstateislockeddownwhentheHttpApplicationinstancethat'sprocessingtherequestfiresanAcquireRequestStateeventandunlockedwhenitfiresaReleaseRequestStateevent.
DoASP.NETformsauthenticationcookiesprovideanyprotectionagainstreplayattacks?
Dothey,forexample,includetheclient'sIP addressoranythingelsethatwoulddistinguishtherealclientfromanattacker?
No.Ifanauthenticationcookieisstolen,itcanbeusedbyanattacker.It'suptoyouto preventthisfromhappeningbyusinganencryptedcommunicationschannel(HTTPS).Authenticationcookiesissuedassessioncookies,do,however,includeatime-outvalidthat limitstheirlifetime.Soastolensessioncookiecanonlybeusedinreplayattacksaslongastheticketinsidethecookieisvalid.Thedefaulttime-outintervalis30minutes.Youcanchangethatbymodifyingthetimeoutattributeac