kia9372 Ответов: 1

Не вводите действие HTTPPOST в ASP core web api


i create aweb service in asp core2.2 and send data from client (angular6).

my controller in Admin area .

this Startup :


<pre lang="c#">
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseSignalR(routes =>
        {
            routes.MapHub<CrudRealTime>("/CrudRealTime");
        });
        app.UseCors("CorsPolicy");
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "areas",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
            );
        });
    }


i use this address for access Create Roles Actoin in RoleManager Controller :

https://localhost:44390/api/role/createrole

but it not enter in action . when i use this role it work : https://localhost:44390/api/role/GetRoles but i dont know whats the problem and how can i solve this .

last time i run the project and it givee data from Client but now it not work . i did not change any things in server code .

how can i solve this problem ????



i create aweb service in asp core2.2 and send data from client (angular6).

my controller in Admin area .

this Startup :

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseSignalR(routes =>
        {
            routes.MapHub<CrudRealTime>("/CrudRealTime");
        });
        app.UseCors("CorsPolicy");
        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "areas",
                template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
            );
        });
    }
i use this address for access Create Roles Actoin in RoleManager Controller :

https://localhost:44390/api/role/createrole

but it not enter in action . when i use this role it work : https://localhost:44390/api/role/GetRoles but i dont know whats the problem and how can i solve this .

last time i run the project and it givee data from Client but now it not work . i did not change any things in server code .

how can i solve this problem ????

RoleAction

What I have tried:

<pre>[HttpPost("CreateRole")]
    public async Task<IActionResult> CreateRole([FromBody]RolePostModel model)
    {
        if (ModelState.IsValid)
        {

            var result = await _roleManag.CreateAsync(new Role(model.description, model.rolelevel, model.name));
            if (result.Succeeded)
            {
                return Ok(Messagesresx.Success_Add_Role);
            }
            else
            {
                return Content(Messagesresx.Fail_Add_Role_In_DataBase);
            }
        }
        else
        {
            return BadRequest();
        }
    }

1 Ответов

Рейтинг:
1

Bohdan Stupak

Трудно понять что - то без фрагмента клиентского кода, вызывающего ваш контроллер. Но самая распространенная причина заключается в том, что форма данных, которые вы публикуете от клиента, не соответствует тому, что вы ожидаете на сервере. Пожалуйста, проверьте это еще раз.