1) What is appsettings.json?
This .json file is holding the application configuration values for a.net core application, this is very similar to web.config or app.config in a legacy .net application
We can have multiple versions of the appsettings.json file
Template: appsettings.[Environment].json
Example:
* appsettings.DevEnv.json
* appsettings.TestEnv.json
* appsettings.Staging.json
* appsettings.json
Little deeper:
In order to load the configuration information into the application from the file we need the following class in the .net : JSON Configuration Provider
Inherited from FileConfigurationProvider
How to use:
var _ConfigurationBuilder = new ConfigurationBuilder(Environment.ApplicationBasePath)
.AddJsonFile("appsettings.Live.json") .AddEnvironmentVariables();
Configuration = _ConfigurationBuilder.Build();
2) What is the difference between ASP.NET CORE with .NET Framework and ASP.NET with .NET Core Framework
ASP.NET CORE with .NET Framework:
This is purely based on Windows OS, any application based on this framework will work only in Windows OS.
ASP.NET CORE with .NET Core Framework
Contrast to the previous one this is platform independent, means not bound to any OS like Linux, Windows, Mac OS.
3) How to Get the username of the
logged user in ASP.NET Core?
Assuming that the application is set to work in Windows Authentication in the launchSettings.json file
"windowsAuthentication": true
private readonly IHttpContextAccessor _httpContextAccessor;
var username = _httpContextAccessor.HttpContext.User.Identity.Name;
4) How to find the IP Address of the client machine
Without Proxy: Using HttpContext.Connection Property
HttpContext context; // Need to initialize
var IPAddress = context.Connection.RemoteIpAddress;
With Proxy we need some workaround: Please see this link for complete steps
5) How to get the query string in the method in ASP.NET Core
var NameQueryString = HttpContext.Request.Query["Name"];
6) What is response buffering in ASP.NET Core?
A large response, usually a file download from the server will take a normal route of streaming the file by dividing it into small chunks and send it to user, as oppose to streaming the whole file will be loaded into the memory to serve as it as to the user
Enabling / Disabling Response Buffering
context.Request.EnableBuffering();
HttpContext.Features.Get<IHttpResponseBodyFeature>().DisableBuffering();
6) What is the default port for ASP.NET
Core?
Answer: 5000
7) In which scenarios the port 5001 is used?
Answer: If the local certificate for secure http (https) is available in the development machine the 5001 port is used
8) Where can I specify the port?
Answer: In appsettings.json file
Example :
{
Kestrel:{
“endpoints”:{
“http”:{
url:”http://localhost:5000”
}
}
}
}
9) What is Kestral?
Answer: In short Kestral is a open source server which runs the ASP.NET Core in any platform
10)Is http:localhost:5000/MyPage is equal to http:localhost:5000/mypage?
Answer: Usually yes until we explicitly set the routing options for the service to lowercase only serviveObj.AddRouting(options => options.LowerCaseUrls = true);
11)And what is the use of setting the LowerCaseUrls?
Answer: Sticking only to a single case (upper of lower URLs) will help the search engine to index the site / page better
The same site
http://mysite.com/help
and
http://MySite.com/Help
both will be indexed as 2 separate pages in the search engines and search landing will be affected by this, so better to stick to one case option, preferably to lower case URL
12)What is the difference between IOC and DI?
Answer: IOC (Inversion of control) is the design target intended to achieve between the classes and their dependencies,
DI (Dependency Injection) is one of the design patterns used to achieve this target
There are other ways to achieve IOC which is subjected to the application type
Comments