不在ASP核心web api中输入HTTPPOST操作 [英] Not enter HTTPPOST action in ASP core web api

查看:94
本文介绍了不在ASP核心web api中输入HTTPPOST操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
        }
    }

推荐答案

如果没有调用控制器的客户端代码片段,很难找出一些东西。但最常见的原因是,您从客户端POST的数据形状与您在服务器上的预期不匹配。请仔细检查一下。
It's hard to figure out something without a snippet of a client code calling your controller. But the most common reason is that the shape of a data you POST from a client mismatches what you expect on a server. Please double check this.


这篇关于不在ASP核心web api中输入HTTPPOST操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆