.NET

    [ASP.NET Core] HttpContext.User

    Controller 라면 User 키워드를 통해서 현재 로그인한 사용자의 정보를 가져올 수 있습니다. 예를 들어 아이디를 검색하려면 다음과 같이 할 수 있습니다. string user = User?.Claims.Where(a => a.Type == ClaimTypes.NameIdentifier)?.FirstOrDefault()?.Value ?? string.Empty; Controller가 아닌 Controller에서 참조하는 외부클래스에서 User개체에 직접 접근해야 한다면 HttpContext를 통해야 합니다. 이를 위해 Program.cs에서 아래와 같이 AddHttpContextAccessor 서비스를 등록하고 builder.Services.AddHttpContextAccessor(); build..

    [ASP.NET Core] Razor Page로 웹프로젝트 만들기

    [ASP.NET Core] Razor Page로 웹프로젝트 만들기

    이번 포스팅에서는 ASP.NET Core의 Razor Page를 사용해 간단한 웹서비스를 구현해 보고자 합니다. 1. HTTP 클라이언트(User-Agent)가 서버와의 통신에서 HTTP를 사용한다는 것은 특정 주소에 대한 HTTP요청을 만들어 서버에 요청하게 되고 서버는 이 요청에 따라 해당 응답을 생성해 클라이언트로 반환하는 구조로 통신함을 의미합니다. 예를 들어 사용자가 웹 브라우저에서 http://cliel.com/ 주소를 입력하면 해당 요청을 서버에 전송하게 되고 서버는 해당 주소에 지정된 서버의 Resource를 반환함으로서 사용자의 웹브라우저에서 반환된 Resource를 표시하게 됩니다. 2. URL 우리가 인터넷 주소라고 칭하는 URL은 세부적으로 다음과 같이 구성되어 있습니다. Schem..

    [ASP.NET Core] IIS 배포 (게시)

    [ASP.NET Core] IIS 배포 (게시)

    ASP.NET 응용program을 IIS에 배포하기 위한 가장 흔한 방법으로 자체 folder(일반적으로 publish)에 project전체를 배포하고 이를 FTP나 단순복사를 통해 IIS의 Web Service가 동작중인 위치에 붙여넣는 방식입니다. 이 방법 외에 IIS Web Server로 곧장 배포하는 방식이 있는데 이에 대해 알아보고자 합니다. 1. 역활 및 기능추가 Web Server에서 아래와 같이 'IIS Mnagement Scripts and Tools(IIS 관리 스크립트 및 도구)'와 'Management Service(관리 서비스)' 역활 그리고 '기본 인증'을 추가합니다. 2. Web Deploy 설치 아래 주소에서 Web Deploy를 내려받아 server에 설치합니다. Micro..

    [Visual Studio IDE] Visual Studio IDE의 Registry 설정

    [Visual Studio IDE] Visual Studio IDE의 Registry 설정

    * Visual Studio IDE라는 표현은 Visual Studio Code와의 명칭에 대한 혼동을 방지하고자 하는 것이며 Visual Studio 2019나 2022등의 IDE를 의미합니다. Visual Studio IDE는 다른 program과 마찬가지로 자신의 설정관리를 위해 Registry를 이용하고 있습니다. 그런데 실제 Windows 운영체제의 Regedit를 뒤져보면 Visual Studio IDE와 관련한 설정을 찾을 수 없는 경우가 많은데 그 이유는 Visual Studio IDE는 이 설정 자체를 별도의 file로 따로 분리하여 관리하고 있기 때문입니다. 실제 Visual Studio 2022의 경우 아래 경로에 있는 C:\Users\Administrator\Local Setting..

    [ASP.NET Core] Session

    1. Service 설정 Startup.cs의 ConfigureServices() method에서 Session을 사용하기 위한 Service를 추가합니다. services.AddDistributedMemoryCache(); services.AddSession(option => { option.Cookie.Name = "mySession"; option.IdleTimeout = TimeSpan.MaxValue; //기본값 20분 }); AddDistributedMemoryCache() method는 Server의 Cache memory를 사용하도록 하기 위한 것으로 Session을 저장하기 위함이며 AddSession()은 Session자체의 설정으로 Cookie.Name으로 Session의 이름을, I..

    [ASP.NET Core] Logging

    [ASP.NET Core] Logging

    1. NuGet Package 설치 NuGet에서 etEscapades.Extensions.Logging.RollingFile package를 project에 설치합니다. 2. Log File 설정 Program.cs를 다음과 같이 수정해 ConfigureLogging method를 설정합니다. Host.CreateDefaultBuilder(args) .ConfigureLogging((hostingContext) => hostingContext.AddFile(options => { options.FileName = "log-"; options.LogDirectory = "Logs"; options.FileSizeLimit = null; //기본 10MB, 단위 MB options.RetainedFileC..

    [ASP.NET Core] Claim 인증과 권한

    [ASP.NET Core] Claim 인증과 권한

    Claim은 특정한 key값을 통해 사용자 인증 및 권한을 관리하며 여기에 필요한 data를 추가하여 사용할 수 있는 인증방법입니다. 1. 기본설정 Startup.cs의 ConfigureServices() method에 인증 및 권한에 관련한 service를 추가합니다. services.AddAuthentication(defaultScheme: CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(option => { option.AccessDeniedPath = "/Home/Error"; option.LoginPath = "/login"; }); services.AddAuthorization(); services.AddHttpContextAcces..

    [ASP.NET Core] 암호화 사용하기(DataProtection)

    1. Class Library형식의 Project를 생성하고 'Microsoft.AspNetCore.DataProtection' 이름의 Nuget package를 설치합니다. 2. project에 다음과 같은 class를 추가해 사용할 암호화 algorithm을 지정합니다. 예제에서는 myWebLibrary라는 이름의 project를 생성하였습니다. using Microsoft.Extensions.DependencyInjection; using System; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel; namespace ..