hi!
If you click btn without logging in on the client side, it is sent to the web api side. However, because of the 401 permission, the list is not visible. Here I try to authenticate by putting a token in the header value. What am I missing? Can’t I make it without login?
web client -> startup.cs
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme,
options => Configuration.Bind("JwtSettings", options));
-----
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
--------
web api -> controller
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class testController : ControllerBase
{
[HttpGet]
pubilc IActionResult Get() {...}
[HttpPost]
pubilc IActionResult Post() {...}
}
------------
client - > form1
string Secret = "xxxxxxxxxxxxxx";
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/json; charset=UTF-8";
httpWebRequest.Headers.Add("Authorization", "Bearer " + Secret);
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = RequestData.Length;