ASP Flashcards
HTML Helpers like @Html… are replaced by what in Core
Tag Helpers
How do you set up Dependency Injection?
there is a ConfigureServices method in the startup.cs class - this is where DI can be set up. Use the services.AddTransient();
There are two special views by default in the Views folder - what are these?
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
In Core, which of these can you use: model first, code first, database first
Only code-first
Why use a “virtual” property on a model when using Entity Framework?
in EF, virtual on a model property makes this lazy-loaded; you can always remove virtual and make the property eager-loaded
Where are connection strings defined in Core?
in core, the connection strings should be in appsettings.json (rather than web.config)
Are configuration settings mainly defined in Web.config in ASP.Net Core?
No - the config.json file is generally not used in Core.
Where are client-side (static) files defined in an ASP.Net Core app?
In Core, there is a wwwroot folder which should hold all static files (JS, CSS, etc)
In a view, how can you conditionally include html when in dev mode?
You can use to include/exclude content in razor views depending on the environment setting
How do view components differ from partial views?
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
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?
[BindNever]
On a form, how can you add a section to show all input errors together?
Add a div with tag helper of asp-validation-summary=”All”
On a form, how can you add a section to show oneinput field’s error?
Add a span or div with tag helper of asp-validation-for=””
In which method do you add functions to the ASP pipeline?
In the Configure method of the Startup class.
In which method do you defined elements for dependency injection?
In the ConfigureServices method of the Startup class
How can you have an action return non-200 status codes?
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
How does an AJAX request specify the data format it would like to get back?
Using the Accept header
How does an AJAX request specify the format of the data it is sending?
Using the content-type header
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?
“Content Negotiation”
What are the default rules for whether asp.net parameter binding uses the query string or the post body?
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
What are the three “lifetimes” that can be used with dependency injection?
Transient - every time object is needed
Scoped - once per request
Singleton - once for app
How do you create use a “custom validation attribute “?
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.
Can an extension method on a class access private members variables?
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.