쿠키추가
Install- package Microsoft.AspNetCore.Authentication.Cookies

publicvoidConfigureServices(IServiceCollectionservices)

{

   // Add framework services.

   services.AddMvc();

   services.AddSingleton<ITempDataProvider, CookieTempDataProvider>();

   services.AddSingleton<IConfigurationRoot>(Configuration);

}

CookieAuthenticationOptions Options = new CookieAuthenticationOptions();
Options.AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme;

Options.LoginPath = new PathString("/Account/Login/");

Options.AutomaticAuthenticate = true;

Options.AutomaticChallenge = true;

Options.CookieHttpOnly = true;

app.UseCookieAuthentication(Options);




'Development > asp.core' 카테고리의 다른 글

.NET Core Entity Framework 사용방법  (0) 2017.02.28

1. PackageManager에서 필요한 기능 설치

Install-Package Microsoft..EntityFrameworkCore –pre

Install-Package Microsoft.EntityFrameworkCore.SqlServer -Pre

Install-Package Microsoft.EntityFrameworkCore.Tools -Pre

Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design -pre


2. DB생성 명령어

Scaffold-DbContext"data source=safetia.com;initialcatalog=데이터베이스명;user id=계정;password=비밀번호;"Microsoft.EntityFrameworkCore.SqlServer-OutputDirModels\DB

3. 서비스에 의존성 주입
- Appsetting.json(Config)에 추가

"ConnectionStrings": {

    "DefaultConnection": "Server=safetia.com;Database=SAFETIA_IS(Temp);Trusted_Connection=True;User Id=sa;Password=zonerock"

  }
- startup.cs 

public void ConfigureServices(IServiceCollection services)

    {

      // Add framework services.

      services.AddMvc();

      services.AddSingleton<IConfigurationRoot>(Configuration);

      services.AddDbContext<SAFETIAContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));     

    }

4. ~Conext파일 관리 

public partial class SAFETIAContext : DbContext

  {

    public SAFETIAContext(DbContextOptions options):base (options)

    {

    }

   //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

    //{

    //}
 }



'Development > asp.core' 카테고리의 다른 글

로그인 설정  (0) 2017.02.28

+ Recent posts