Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i create aweb service in asp core2.2 and send data from client (angular6).

my controller in Admin area .

this Startup :


C#
<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();
        }
    }
Posted
Updated 27-Feb-19 23:39pm

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900