I have a function that checks whether a user already exists by looking through the database to see if the email registered has already been used. The function accepts the email address as a parameter, and can be seen below:
[Route("api/[controller]")]
[ApiController]
public class ReportController : ControllerBase
{
[HttpPost]
[Route("UserExists")]
private bool UserExists(string EmailAddress)
{
using var db = new NorthwindContext();
var user = db.UserLogin.Where(zz => zz.EmailAddress == EmailAddress).FirstOrDefault();
return user != null;
}
}
Now, using PostMan I am trying to pass an email address to check what the function returns, if my understanding is correct, it should be either true or false, considering the function is of type bool.
However, PostMan indicates that the requested resource cannot be found:

My Startup.cs file:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace INF354ReportHomework
{
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.AddCors(options => options.AddDefaultPolicy(
builder =>
{
builder.AllowAnyOrigin();
builder.AllowAnyHeader();
builder.AllowAnyMethod();
}));
services.AddControllers();
}
// 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.UseHttpsRedirection();
app.UseRouting();
app.UseCors();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
try to change UserExists method from private to public, controllers methods should be public.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With