1-) .Net 6 Core Web Api - .Net 6 Core Web Api Basit Kullanımı
http://192.168.1.102:15550/api/Ogrenci
iis kurma ve ssl yapma : https://youtu.be/79z8Ppqz1sA
http://localhost:15550/swagger/index.html
github link : https://github.com/ramazanhaber/NetCoreV2
|
1- NUGET MANAGERDEN İNDİR
Install-Package Microsoft.EntityFrameworkCore -Version 7.0.1 Install-Package Microsoft.EntityFrameworkCore.Tools -Version 7.0.1 Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 7.0.1 |
1.1- Program.cs
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseCors(builder => builder .AllowAnyHeader() .AllowAnyMethod() .SetIsOriginAllowed((host) => true) .AllowCredentials() );
if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c =>{ c.SwaggerEndpoint("/swagger/v1/swagger.json", "myapi v1"); }) ; }
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
|
2- Context.cs
using Microsoft.EntityFrameworkCore;
namespace NetCoreV2.DataAccesLayer { public class Context : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Data Source=RAMBO3;Initial Catalog=Deneme;User ID=sa;Password=123456;TrustServerCertificate=True"); } public DbSet<Ogrenci> Ogrenci { get; set; } } } |
3- Ogrenci.cs
using System.ComponentModel.DataAnnotations;
namespace NetCoreV2.DataAccesLayer { public class Ogrenci { [Key] public int id { get; set; } public string ad { get; set; } public int yas { get; set; } public string? alan { get; set; } } } |
4- OgrenciController.cs
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NetCoreV2.DataAccesLayer;
namespace NetCoreV2.Controllers { [Route("api/[controller]")] [ApiController] public class OgrenciController : ControllerBase { [HttpGet] public IActionResult EmployeeList() { using var c = new Context(); var values = c.Ogrenci.ToList(); return Ok(values); }
[HttpPost] public IActionResult EmployeeAdd(Ogrenci employee) { using var c = new Context(); c.Add(employee); c.SaveChanges(); return Ok(); } } } |
PROJEYİ PUBLİSH ETME
SON OLARAK İİS KURULUMU .NET 6
BURADAN İNDİR | https://drive.google.com/file/d/1HH3dfMpVXy3voW88cEUznRmKM-JJMV0I/view?usp=sharing
|
VEYA BURADAN İNDİR |
https://dotnet.microsoft.com/en-us/download/dotnet/6.0
|
|
MOBİLEDEN ULAŞIP TEST İÇİN KULLANMAK İÇİN conveyer olarak extension yükle
projende debug yapmak için : https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti kaynak : https://www.youtube.com/watch?v=9ixt9bdAHs8&ab_channel=Asfendyar
|
AYRICA BAKINIZ iis swagger getirme kaynak
https://stackoverflow.com/questions/62397386/swagger-ui-not-displaying-when-deploying-api-on-iis