'Postman post request error "The Route Data field is required" and " The HttpContext field is required."

post request

{
    "FullName":"123",
    "Password":"123"
}

Here is the postman error.


{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-c6c66dedbd981c409a0b5011bfc83ca7-0c6499593cff6f4b-00",
    "errors": {
        "ControllerContext.RouteData": [
            "The RouteData field is required."
        ],
        "ControllerContext.HttpContext": [
            "The HttpContext field is required."
        ]
    }
}

'''


My project was crushed and I rewrite it. My Database is already the past one. And I made the migration and update the database. When I was trying to log in with exists user I can. But when I try to register using angular or postman it gives an error. I can not handle the problem and I searched then I got nothing to do.


here my register method:

public async Task<Object> PostUser(UserModel model)
{

    var user = new User()
    {
        FullName = model.FullName,

    };
    try
    {
        var result = await _userManager.CreateAsync(user, model.Password);
        return Ok(result);
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddCors(o => o.AddPolicy("AllowAnyCorsPolicy", builder =>
    {
        builder.AllowAnyOrigin()
            .AllowAnyMethod()
            .AllowAnyHeader();
    }));

    //D.injection
    services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
    services.AddDbContext<AuthenticationContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
    services.AddIdentity<User, IdentityRole>().AddEntityFrameworkStores<AuthenticationContext>();
    services.Configure<IdentityOptions>(options =>
    {
        options.Password.RequireDigit = false;
        options.Password.RequireNonAlphanumeric = false;
        options.Password.RequireLowercase = false;
        options.Password.RequireUppercase = false;
        options.Password.RequiredLength = 4;
    });

    //JWT Auth
    var key = Encoding.UTF8.GetBytes(Configuration["ApplicationSettings:JWT_Secret"].ToString());
    services.AddAuthentication(x =>
    {
        x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
        x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    }).AddJwtBearer(x =>
    {
        x.RequireHttpsMetadata = false;
        x.SaveToken = true;
        x.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuerSigningKey = true,
            IssuerSigningKey = new SymmetricSecurityKey(key),
            ValidateIssuer = false,
            ValidateAudience = false,
            ValidateLifetime = false,
        };

    });



}

// 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();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }

app.UseStaticFiles();


    app.UseRouting();
    app.UseCors(builder =>
        builder.WithOrigins(Configuration["ApplicationSettings:Client_URL"].ToString())
            .AllowAnyHeader()
            .AllowAnyMethod()
    );

app.UseAuthorization();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapRazorPages();
        endpoints.MapControllers();
    });
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source