This post is about ASP.NET Core Interview Questions. These questions are good enough to assess a candidate if he/she has working knowledge about Asp.Net Core, These are kind of guidelines for core ASP.NET Core concepts and some experience in real-time application development using Asp.net Core.
Top Online Courses 2021 (Offering Discount)
If you are job seeker or going for ASP.NET Core interviews, this will help you to get ready for potential questions be asked during interview.
If you are beginner, then i suggest you should go through basic .net framework related questions first, which will remain almost same for all frameworks, here they are!
What is CTS?
Learn more about Common Type System.
What is CLR?
Learn more about Common Language Runtime.
What is CLS?
Learn more about Common Language Specification.
What is FCL?
Learn more about Framework Class Library.
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
//"Default": "Warning"
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"DbConnectionConfig": {
"DatabaseName": "databaseName",
"UserName": "username",
"Password": "password",
"ServerName": "IP-Address"
}
}
Learn more about asp.net core middleware.
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddMvc().AddRazorOptions(opt =>
{
opt.PageViewLocationFormats.Add("/Pages/shared/{0}.cshtml");
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
}
}
It defines the HTTP pipeline, how the application will respond to request. We can change the sequence of middleware configuration, it accepts IApplicationBuilder as a parameter and two optional parameters: IHostingEnvironment and ILoggerFactory.
Using this method, we can configure built-in middleware such as authentication, error handling and also any custom middleware or third-party middleware.
Both methods are used to add middleware delegate to the application request pipeline.
Use method may call the next middleware in the pipeline.Run method never calls the subsequent ore next middleware, After IApplicationBuilder.Run method, system stops adding middleware in pipeline
The middleware for the session is provided by Microsoft.AspNetCore.Session. To use the session in ASP.NET Core application we need to add the middleware in pipeline
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddSession();
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSession();
}
}
When we create a razor page, it provides the option to have model binging or not, in model binding there is a model created with the razor page, the model is inherited from : PageModel we need to use [BindProperty] attribute to bind any property to model
Here is an examplepublic class ContactModel : PageModel
{
[BindProperty]
public string StudentName { get; set; }
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
Represents HTML and markup.
Represent JSON that can be used in AJAX, like a JSON object
Represent a JavaScript script.
Represents string literal.
Represents a redirection to a new URL
Represent another action of same or other controller
Returns HTML from Partial view
Returns HTTP 403 status
Represents the content of a file
We can write following code in Startup.cs file.
Here are some sample two Middleware pipeline, we want to map them for different path.
private static void ExecuteMiddleware1(IApplicationBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync("Execute Middleware 1");
});
}
private static void ExecuteMiddleware2(IApplicationBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync("Execute Middleware 2");
});
}
Here is how you can Map Middleware in Configure method
public void Configure(IApplicationBuilder app)
{
app.Map("/mapPath1", ExecuteMiddleware1);
app.Map("/mapPath2", ExecuteMiddleware2);
app.Run(async context =>
{
await context.Response.WriteAsync("Hello from No Match.");
});
}
Hope these above questions answer will help you to get ready for asp.net core interview, if you have more time, please check our free Asp.net Core tutorial with Code Sample
Here are some Asp.net core development service providers who often asks similar type of question when asses any candidate.