I have a problem to return windows authentication in angular 4.
I'm using net Core and I get the following error:
status code - 401 Unauthorized
I tried the same method in net Framework and it is working.
I think the problem is when I want to send data to angular; the save method is called once, only with the request method: OPTIONS, while in net Framework is called twice: OPTIONS => POST.
How I can fix this problem in net Core? Any ideas will be helpful.
Save method :
namespace TestAuthorization.API.Controllers
{
[Authorize]
[Route("data")]
public class DataController: Controller
{
[HttpPost]
[Route("save")]
public IActionResult Save(PostData data)
{
return Ok(data.ToString());
}
}
}
Startup class:
namespace TestAuthorization.API
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
services.AddMvc();
services.AddCors();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
app.UseCors(builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseStaticFiles();
app.UseDefaultFiles();
app.UseMvc();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Mvc did not find anything!");
});
}
}
}