첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
다운로드

▶ appsettings.json

{
    "Position" :
    {
        "Title" : "Editor",
        "Name"  : "Smith"
    },
    "TestKey"  : "Test Value",
    "Logging"  :
    {
        "LogLevel" :
        {
            "Default"                    : "Information",
            "Microsoft"                  : "Warning",
            "Microsoft.Hosting.Lifetime" : "Information"
        }
    },
    "AllowedHosts" : "*"
}

 

728x90

 

▶ Controllers/TestController.cs

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Text;

namespace TestProject.Controllers
{
    /// <summary>
    /// 테스트 컨트롤러
    /// </summary>
    public class TestController : Controller
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 구성
        /// </summary>
        private IConfiguration configuration;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - TestController(configuration)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="configuration">구성</param>
        public TestController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 인덱스 페이지 처리하기 - Index()

        /// <summary>
        /// 인덱스 페이지 처리하기
        /// </summary>
        /// <returns>액션 결과</returns>
        public IActionResult Index()
        {
            string testValue       = this.configuration["TestKey"                 ];
            string title           = this.configuration["Position:Title"          ];
            string name            = this.configuration["Position:Name"           ];
            string defaultLogLevel = this.configuration["Logging:LogLevel:Default"];

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine($"Test Key          : {testValue}"      );
            stringBuilder.AppendLine($"Title             : {title}"          );
            stringBuilder.AppendLine($"Name              : {name}"           );
            stringBuilder.AppendLine($"Default Log Level : {defaultLogLevel}");

            return Content(stringBuilder.ToString());
        }

        #endregion
    }
}
728x90
그리드형(광고전용)

'C# > ASP.NET MVC' 카테고리의 다른 글

[C#/ASP.NET MVC/.NETCORE] CommandLineConfigurationExtensions 클래스 : AddCommandLine 확장 메소드를 사용해 명령줄 구성 공급자 등록하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] EnvironmentVariablesExtensions 클래스 : AddEnvironmentVariables 확장 메소드를 사용해 환경 변수 구성 공급자 등록하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] OptionsConfigurationServiceCollectionExtensions 클래스 : Configure 확장 메소드를 사용해 설정 값을 서비스 컨테이너에 추가하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] ConfigurationBinder 클래스 : Get 확장 메소드를 사용해 특정 섹션의 설정 값 구하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] ConfigurationBinder 클래스 : Bind 확장 메소드를 사용해 특정 섹션의 설정 값을 객체와 바인딩하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] IConfigurationRoot 인터페이스 : Providers 속성을 사용해 구성 공급자 조회하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] UseWhenExtensions 클래스 : UseWhen 확장 메소드를 사용해 조건부 미들웨어 대리자 추가하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] MapWhenExtensions 클래스 : MapWhen 확장 메소드를 사용해 조건을 만족하는 요청 경로에 대해 미들웨어 파이프라인 분기하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] MapExtensions 클래스 : Map 확장 메소드를 사용해 다계층 요청 경로에 대해 미들웨어 파이프라인 분기하기  (0) 2020.10.21
[C#/ASP.NET MVC/.NETCORE] MapExtensions 클래스 : Map 확장 메소드를 사용해 중첩되는 요청 경로에 대해 미들웨어 파이프라인 분기하기  (0) 2020.10.21
Posted by icodebroker
,