Professional Documents
Culture Documents
1. When calling async methods, what will you do to make sure the
execution completes before processing the rest of the code?
Await keyword
2. How will you call REST API methods from C#?
Using httpclient class
3. How will you find whether an array of integers has the integer i am looking for
using LINQ?
Using Contains() method
4. Use of Generics
A generic type is declared by specifying a type parameter in an
angle brackets after a type name, e.g. TypeName<T> where T is a
type parameter.
Exception handling and logging
Try catch finally blocks
Looging can be done by eventlogs
6. How will you make sure an object is disposed?
Finalize : which is called by the Garbage Collector before when application is running
low memory resources
Dispose:by implementing the idispose interface
MVC:
View Result
Partial View Result
Redirect Result
Redirect To Action Result
Redirect To Route Result
Json Result
File Result
Content Result
Say i want to download a file on click of a link, what action result you would return?
fileresult
3. Is it possible to have more than one attribute routing for a method?
Yes ,we can take two route attributes
4. What will you do to avoid CORS issue when calling ASP.Net API from Angular
services?
5. Have you noticed web.config in Views folder in MVC app? What does it do?
web.config file exists in the Views folders to prevent access to your views by any means
other than your controller.
In razor syntax, how will you escape HTML elements inside a code block
ould use @: to escape:
@if(Model.foo)
{
@:Hello World
}
or the special <text> tag which is not outputted in the response:
@if(Model.foo)
{
<text>Hello World</text>
}
7. When the app is running, what will happen if i go and make changes to the
web.config?
Website will restarts,allthe session will loose
8. How will you redirect the users to custom pages based on the http error code?
Using redirect result we can redirect in exception filter
1. public void OnException(ExceptionContext filterContext)
2. {
3. if (!filterContext.ExceptionHandled && filterContext.E
xception is NullReferenceException)
4. {
5. filterContext.Result = new RedirectResult("customE
rrorPage.html");
6. filterContext.ExceptionHandled = true;
7. }
8. }
9. }
Html.Partial() Html.RenderParti
Html.Partial returns html string. Html.RenderPartial returns void.
Html.Partial injects the html string of the partial view into the Html.RenderPartial writes html
main view. stream.
Performance is slow. Perform is faster compared with H
Html.Partial() need not to be inside the braces. Html.RenderPartial must be inside
11.
10. How will you override Main layout inheritence for a view?
Using sublayout and renderbody
12. How will you maintain state in a MVC application?
13. Viewbag and viewdata and tempdata
12. ViewBag, ViewState, and TempData - What do these do and when to use what?
ViewData ViewBag TempData
It is Key-Value Dictionary It is Key-Value Dictionary
It is a type object
collection collection
ViewData is a dictionary ViewBag is Dynamic TempData is a dictionary
object and it is property property of ControllerBase object and it is property
of ControllerBase class class. of controllerBase class.
ViewData is Faster than ViewBag is slower than
NA
ViewBag ViewData
TempData is also
ViewData is introduced ViewBag is introduced in
introduced in MVC1.0
in MVC 1.0 and available MVC 3.0 and available in
and available in MVC 1.0
in MVC 1.0 and above MVC 3.0 and above
and above.
ViewData also works ViewBag only works TempData also works
with .net framework 3.5 with .net framework 4.0 and with .net framework 3.5
and above above and above
In depth, ViewBag is used
Type Conversion code is Type Conversion code is
dynamic, so there is no need
required while required while
to type conversion while
enumerating enumerating
enumerating.
Its value becomes null if TempData is used to
redirection has Same as ViewData pass data between two
occurred. consecutive requests.
TempData only works
It lies only during the
Same as ViewData during the current and
current request.
subsequent request
14. What's the use of filters in MVC and what scenarios you can use it? Exception
Handling, Authorization etc. using filters
Inject logic pre or post to an action method execute
15. Bundling and Minification in MVC
Bundling and minification techniques were introduced in MVC
4 to improve request load time. Bundling allows us to load
the bunch of static files from the server in a single HTTP
request.
Minification technique optimizes script or CSS file size by
removing unnecessary white space and comments and
shortening variable names to one character.
16. Different types of authentication - Forms, Windows etc. When to use what?
Web applications are3 using forms authentication it comes under the namespace
system.web.security
Using setauthenticate method we can store the user information it sets the
request.isauthenticate to true based on this we can authenticate the users
16. How will you prevent XSS attacks? Hint. HttpAntiForgeryToken
Using the @Html. AntiforgeryToken()