我试图在我的项目中创建一个新的和第一个端点。
是否有任何安全问题?
会很感激帮助,
这是我的PROGRAM
文件:
global using myDB_Files.Models;
global using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddControllers();
builder.Services.AddDbContext<myDBContext>(opt =>
opt.UseSqlServer(connectionString));
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwaggerUI();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseSwagger(x => x.SerializeAsV2 = true);
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html"); ;
app.Run();
这是我的控制器,如果我从浏览器以这种方式访问它,我根本不来调试器:
https://localhost:5020/api/Translate
代码:
using Microsoft.AspNetCore.Mvc;
{
[Route("api/[controller]")]
[ApiController]
public cl TryMeController : ControllerBase
{
private readonly myDBContext _context;
public TryMeController(myDBContext context)
{
_context = context;
}
[HttpGet("Translate")]
public string GetCases()
{
return "tryme";
}
}
}
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(33条)