Reputation: 2274
I build the Blazor with template Blazor Server, Webassembly, Shared. It is working okay.
But when I try to test with postman. It always show this
the below is my testing controller. i can use blazor httpclient to access rest. but i want to test with postmna
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SchoolHero.Server.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SchoolHero.Server.Controllers.V1
{
[ApiVersion("1.0")]
[AllowAnonymous]
public class BuggyController : BaseApiController
{
private readonly ApplicationDbContext _context;
public BuggyController(ApplicationDbContext context)
{
_context = context;
}
[HttpGet("testauth")]
[Authorize]
public ActionResult<string> GetSecretStuff()
{
return "super secret";
}
[HttpGet("notfound")]
public ActionResult GetNotFoundRequest()
{
var thing = _context.Developers.Find(46);
if (thing == null)
{
return NotFound();
}
return Ok();
}
[HttpGet("servererror")]
public ActionResult GetServerError()
{
var thing = _context.Developers.Find(46);
var thingToReturn = thing.ToString();
return Ok();
}
[HttpGet("badrequest")]
public ActionResult GetBadRequest()
{
return BadRequest();
}
[HttpGet("badrequest/{id}")]
public ActionResult GetNotFoundWithId(int id)
{
return BadRequest();
}
}
}
/// This is the startup class. I register. Seemd fine
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.ResponseCompression; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using SchoolHero.Server.Extensions; using System.Linq; using System.Threading.Tasks;
namespace SchoolHero.Server {
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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddContextInfrastructure(_configuration);
services.AddEssentials();
services.AddIdentityService(_configuration);
services.AddControllersWithViews();
services.AddRazorPages();
services.AddCors(o => o.AddPolicy("CorsPolicy", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebAssemblyDebugging();
}
else
{
app.UseExceptionHandler("/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.UseCors("CorsPolicy");
app.ConfigureSwagger();
app.UseHttpsRedirection();
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
endpoints.Map("api/{**slug}", HandleApiFallback);
endpoints.MapFallbackToFile("index.html");
});
}
private Task HandleApiFallback(HttpContext context)
{
context.Response.StatusCode = StatusCodes.Status404NotFound;
return Task.FromResult(0);
}
} }
Upvotes: 0
Views: 713
Reputation: 398
No code at all? All I can say from that is that appears like you're sitting on an authentication loop.
Upvotes: 1