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

TestProject.zip
다운로드

▶ appsettings.json

{
    "TestKey"  : "TestValue1",
    "Position" :
    {
        "Title" : "Editor1",
        "Name"  : "Smith1"
    },
    "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.Collections.Generic;
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()
        {
            IConfigurationSection section = this.configuration.GetSection("Position");

            IEnumerable<IConfigurationSection> childSectionEnumerable = section.GetChildren();

            StringBuilder stringBuilder = new StringBuilder();

            foreach(IConfigurationSection childSection in childSectionEnumerable)
            {
                stringBuilder.AppendLine($"{childSection.Key} : {section[childSection.Key]}");
            }

            return Content(stringBuilder.ToString());
        }

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

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

[C#/ASP.NET MVC/.NETCORE] IOptions<T> 인터페이스 사용하기  (0) 2020.10.23
[C#/ASP.NET MVC/.NETCORE] IConfiguration 인터페이스 : @inject문을 사용해 뷰에서 설정 값 구하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] ConfigurationProvider 클래스 : 커스텀 구성 공급자 사용하기 (인메모리 데이터베이스 사용)  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] ConfigurationBinder 클래스 : Get 확장 메소드를 사용해 배열 바인딩하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] ConfigurationExtensions 클래스 : Exists 확장 메소드를 사용해 구성 하위 섹션 존재 여부 구하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] IConfiguration 인터페이스 : GetSection 메소드를 사용해 구성 하위 섹션 구하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] ConfigurationBinder 클래스 : GetValue 확장 메소드를 사용해 특정 키의 단일 설정 값 구하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] MemoryConfigurationBuilderExtensions 클래스 : AddInMemoryCollection 확장 메소드를 사용해 메모리 구성 공급자 등록하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] KeyPerFileConfigurationBuilderExtensions 클래스 : AddKeyPerFile 확장 메소드를 사용해 파일별 키 구성 공급자 등록하기  (0) 2020.10.22
[C#/ASP.NET MVC/.NETCORE] XmlConfigurationExtensions 클래스 : AddXmlFile 확장 메소드를 사용해 XML 구성 공급자 등록하기  (0) 2020.10.22
Posted by icodebroker
,