контроллеров API. Но когда я вызываю метод, Chrome отправляет это:
http://localhost:44333/api/GradesReader ... TION_RESET jquery.min.js:2
Вот мой проект API Startup.cs:
Код: Выделить всё
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(x => x.Filters.Add(new AuthorizeFilter())).AddXmlSerializerFormatters()
.AddXmlDataContractSerializerFormatters();
//For the personal exception handling...
//services.AddMvc(config =>
//{
// config.Filters.Add(typeof(DiaryExceptionFilter));
//});
services.AddDbContext();
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(opt =>
{
opt.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = redirectContext =>
{
redirectContext.HttpContext.Response.StatusCode = 401;
return Task.CompletedTask;
},
OnRedirectToAccessDenied = redirectContext =>
{
redirectContext.HttpContext.Response.StatusCode = 401;
return Task.CompletedTask;
}
};
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
services.AddCors(); //Ezt raktuk bele!
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
//app.UseExceptionHandler("/Home/Error");
//// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
//app.UseHsts();
app.UseExceptionHandler(
options =>
{
options.Run(async context =>
{
context.Response.StatusCode = 500;
context.Response.ContentType = "application/json";
//var ex = context.Features.Get();
//if (ex != null)
//{
// await context.Response.WriteAsync(ex.Error.Message);
//}
});
});
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapControllerRoute(
// name: "default",
// pattern: "{controller=Home}/{action=Index}/{id?}");
//});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.UseCors(opt => opt.WithOrigins("https://localhost:44333/"));
}
}
Код: Выделить всё
[HttpGet("getTest")]
public string GetTest()
{
return "TEST";
}
`
Код: Выделить всё
$(document).ready(function () {
$("#myButton").click(function () {
$.ajax({
url: 'http://localhost:44333/api/GradesReader/getTest/',
type: 'GET',
/*cache: false,*/
/*dataType = 'json',*/
success: function (result) {
console.log(result);
}
});
});
});
Test API
`
Подробнее здесь: https://stackoverflow.com/questions/681 ... et-message
Мобильная версия