• Register
360 points
8 4 2

Want to solve programming problems and get paid for it? If that sounds interesting to you then contact us.

How many types of single page application templates provided by the dot net core?

 Following types of a single page, application templates are available in dot net core

 

Angular

React

React with Redux

JavaScript Services


 

What are tag helpers in asp.net core?

Asp.net core provides an in-build tag helper, Tag helper enables the server-side code that creates and renders the HTML elements in the Razor page.

 

Example: 

 

<input asp-for="Email" class="form-control" />



 

How to enable Session in ASP.NET Core?

The middleware for the session is provided by the package Microsoft.AspNetCore.Session. To use the session in ASP.NET Core application, we need to add this package to csproj file and add the Session middleware to ASP.NET Core request pipeline.

 

 

 public class Startup

 {

 public void ConfigureServices(IServiceCollection services)

 {

 ….

 ….

 services.AddSession();

 services.AddMvc();

 }

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)

 {

 ….

 ….

 app.UseSession();

 ….

 ….

 }

 }



 

What are the various JSON files available in ASP.NET Core?

There are following JSON files in ASP.NET Core :

 

  • global.json

  •  
  • launchsettings.json

  •  
  • appsettings.json

  •  
  • bundleconfig.json

  •  
  • bower.json

  •  
  • package.json


 

What are the different ways for bundling and minification in ASP.NET Core?

There are different ways for doing bundling and minification in ASP.NET Core.

 

  • Gulp – was the default choice for ASP.NET Core till beta versions. Later it was removed due to performance and speed issue and replaced with BundlerMinifier. Read this post to find out the reasons of this decision.

  • BundlerMinifier – is a Visual Studio extension and it’s default choice now. You should see bundleconfig.json file in your default template. Read this post to know more about bundling and minification in ASP.NET Core.

  • ASP.NET Core Web Optimizer – ASP.NET Core middleware for bundling and minification of CSS and JavaScript files at runtime.

  • Grunt – can also be used with ASP.NET Core.



 

Does real-time application support by dot net core?

Yes, Asp.net's core signalR is an open-source library that gives real-time web functionality to the application.

 

What is the difference between app.Run and app.Use in asp.net core middleware pipeline?

Both are used to add middleware delegate to the application request pipeline. 

 

app.Run(): Insert a middleware without invoking the next middleware. It is just run.

 

app.Use(): Insert a middleware into the pipeline which invokes the next middleware.

 

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

{

    app.Use(async (context, next) =>

    {

        await context.Response.WriteAsync("Return from app.Use");

        await next();

    });

    app.Run(async context => {

 

       await context.Response.WriteAsync("Return from app.Run");

 

    });

 

 //Below app.Use will not execute as app.Run does not execute next middleware

    app.Use(async (context, next) =>

    {

        await context.Response.WriteAsync("Return from app.Use");

        await next();

    });

}



 

How to disable Tag Helper at element level?

We can disable Tag Helper at element level using the opt-out character ("!"). This character must apply opening and closing the Html tag.

 

Example

 <!span asp-validation-for="phone" class="divPhone"></!span>



 

What are Razor Pages in ASP.NET Core?

This is a new feature introduced in ASP.NET Core 2.0. It follows a page-centric development model just like ASP.NET web forms. It supports all the feature of ASP.NET Core.

 

Example

 @page 

 <h1> Hello, Book Reader!</h1> 

 <h2> This is Razor Pages </h2>

The Razor pages start with the @page directive. This directive handle request directly without passing through the controller. The Razor pages may have code behind file, but it is not really code-behind file. It is class inherited from PageModel class.




 

What is wwwroot folder in ASP.NET Core?

In ASP.NET Core, all the static resources, such as CSS, JavaScript, and image files are kept under the wwwroot folder (default). You can also change the name of this folder.



 

What is launchSettings.json file in asp.net core?

It holds the project-specific configuration to launch the application including the environment variable.

 

//launchSettings.json

{

  "iisSettings": {

    "windowsAuthentication": false,

    "anonymousAuthentication": true,

    "iisExpress": {

      "applicationUrl": "http://localhost:63977",

      "sslPort": 44389

    }

  },

  "profiles": {

    "IIS Express": {

      "commandName": "IISExpress",

      "launchBrowser": true,

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

    },

  "TestApp": {

      "commandName": "Project",

      "launchBrowser": true,

      "applicationUrl": "https://localhost:5001;http://localhost:5000",

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

    }

  }

}




 

What are discontinued Technologies in .NET Core?

  • Reflection

  • AppDomain

  • Remoting

  • Binary serialization

  • Sandboxing



 

How can we inject the service dependency into the controller?

There are three easy steps to add custom service as a dependency on the controller.

 

Step 1: Create the service

 

 public interface IHelloWorldService

 {

 string SaysHello();

 }

 

 public class HelloWorldService: IHelloWorldService

 {

 public string SaysHello()

 {

 return "Hello ";

 }

 }

Step 2: Add this service to Service container (service can either added by singleton, transient or scoped)

 

 public void ConfigureServices(IServiceCollection services)

 {

 ….

 …

 services.AddTransient<IHelloWorldService, HelloWorldService>();

 …

 …

 }

Step 3: Use this service as a dependency in the controller

 

 public class HomeController: Controller

 {

 IHelloWorldService _helloWorldService;

 public HomeController(IHelloWorldService helloWorldService)

 {

 _helloWorldService = helloWorldService;

 }

 }











 

Sources Used

www.dotnettricks.com

360 points
8 4 2