ASP Flashcards

1
Q

HTML Helpers like @Html… are replaced by what in Core

A

Tag Helpers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you set up Dependency Injection?

A

there is a ConfigureServices method in the startup.cs class - this is where DI can be set up. Use the services.AddTransient();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

There are two special views by default in the Views folder - what are these?

A

there is a _ViewStart.cshtml file in the main Views folder - anything in this file will be first added to the top of each view when rendered. And there is a _ViewImports.cshtml file in the main Views folder - anything in this file will be added as Imports to all views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In Core, which of these can you use: model first, code first, database first

A

Only code-first

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why use a “virtual” property on a model when using Entity Framework?

A

in EF, virtual on a model property makes this lazy-loaded; you can always remove virtual and make the property eager-loaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where are connection strings defined in Core?

A

in core, the connection strings should be in appsettings.json (rather than web.config)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Are configuration settings mainly defined in Web.config in ASP.Net Core?

A

No - the config.json file is generally not used in Core.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Where are client-side (static) files defined in an ASP.Net Core app?

A

In Core, there is a wwwroot folder which should hold all static files (JS, CSS, etc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In a view, how can you conditionally include html when in dev mode?

A

You can use to include/exclude content in razor views depending on the environment setting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do view components differ from partial views?

A

View components - like partial views but allows access to data from view; can have more logic; must be used from view ( partial can be used as stand alone view); you create class and a view for the component - so more code oriented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What data annotation can you use to specify a property of a model should never be sent back when model is bound in a form?

A

[BindNever]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

On a form, how can you add a section to show all input errors together?

A

Add a div with tag helper of asp-validation-summary=”All”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

On a form, how can you add a section to show oneinput field’s error?

A

Add a span or div with tag helper of asp-validation-for=””

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In which method do you add functions to the ASP pipeline?

A

In the Configure method of the Startup class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In which method do you defined elements for dependency injection?

A

In the ConfigureServices method of the Startup class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How can you have an action return non-200 status codes?

A

Actions in controllers can return an IActionResult which includes the http response code. You can use Ok(), NotFound() and BadRequest() to return 200, 400, 404 codes

17
Q

How does an AJAX request specify the data format it would like to get back?

A

Using the Accept header

18
Q

How does an AJAX request specify the format of the data it is sending?

A

Using the content-type header

19
Q

What is the term used to describe the process by which a client (AJAX) request asks for one or more return data types and the server decides what type it is able to return?

A

“Content Negotiation”

20
Q

What are the default rules for whether asp.net parameter binding uses the query string or the post body?

A

Primitive data types (or types convertible to primitive types) default to using query string binding; non-primitive data types default to using the post body.

To override defaults, use the [fromBody], and [fromUri] parameter annotations

21
Q

What are the three “lifetimes” that can be used with dependency injection?

A

Transient - every time object is needed

Scoped - once per request

Singleton - once for app

22
Q

How do you create use a “custom validation attribute “?

A

Create a class which implements IModelValidator. Have the validate method return a list of mode validation errors, or an empty list if all ok. Use as any validation with an attribute on the property in the model class.

23
Q

Can an extension method on a class access private members variables?

A

No, extension methods turn in to static methods which are called with the first parameter as the instance object - so the extension method is not actually on the class, and looks like an external method - so no access to private members.