Today, I am going to cover the latest and cutting edge technology related point.
That is an ASP.NET Core 1.0 (MVC 6) from Microsoft.
Here I am sharing my experience with you for MVC 6 application. We know in the previous version for MVC application, we have web.config file but in the newer version of MVC application, we don't have.
In MVC 6 configuration managed by.json file so when you create a new application for ASP.NET 5 (ASP.NET CORE 1.0) at the time you will see few .json file in solution explorer.
One of the JSON file names is appsettings.json which we can similar to web.config file from the previous version of the application.
So we can configure all setting under the appsettings.json file like connection string and custom settings.
More talking about AppSettings tag under the appsettings.json file where we can set custom key/value data which will be used later in the application.
Here we can see step by step configuration and how to read the AppSettings values.
1. How to set AppSettings in appsettings.json file.
That is an ASP.NET Core 1.0 (MVC 6) from Microsoft.
Here I am sharing my experience with you for MVC 6 application. We know in the previous version for MVC application, we have web.config file but in the newer version of MVC application, we don't have.
In MVC 6 configuration managed by.json file so when you create a new application for ASP.NET 5 (ASP.NET CORE 1.0) at the time you will see few .json file in solution explorer.
One of the JSON file names is appsettings.json which we can similar to web.config file from the previous version of the application.
So we can configure all setting under the appsettings.json file like connection string and custom settings.
More talking about AppSettings tag under the appsettings.json file where we can set custom key/value data which will be used later in the application.
Here we can see step by step configuration and how to read the AppSettings values.
1. How to set AppSettings in appsettings.json file.
Added few settings 1. WebSiteURL and 2.WebSiteTitle.
2. How to configure in Startup,cs file
Added service configuration under the ConfigurationService method as a display in the image.
3. Added model for AppSettings values. So before adding configuration on Startup page we require one model which has same property name declare's in AppSettings.
4. How to used in the controller with dependency inject.
Pass parameter IOptions settings in controller constructor for dependency injection.
Under the constructor, assign values to local variables and use in the controller actions. you can see in screenshots. we have assign value into ViewBag for WebSiteURL and WebSiteTitle and display on view.
0 comments:
Post a Comment