I have error 404 couldn't load resources when using post man to send post request to authunticationcontroller/PostUserLogin
I spend more time but in last not worked or not hit breakpoints on action PostUserLogin .
i move action PostUserLogin to controler MenuController and send post request by post man it worked and breakpoints hitted why this happen
what is wrong on my code
I need when put action PostUserLogin on Authunticationcontroller and send post request to authunticationcontroller/postuserlogin using post man breakpoint not hit .
when put break point on menu controller action PostUserLogin then press click button for send post request breakpoint hitted and it work
but when using another controller name Authuntication and put action PostUserLogin on it and i put breakpoints for test it is not sending post by post man why
and display error 404 why and hot to solve this problem
why authunticationcontroller/postuserlogin not working or breakpoint hit
my code as below
public class ApiRoutes
{
public const string SecurityBase = "Security";
public static class Security
{
public const string GetUserMenus = SecurityBase + "/UserPrograms/{userId}";
}
//Api url For Login
public const string SecurityLogin = "Authuntication";
public static class Login
{
public const string UserLogin = SecurityLogin + "/login";
}
}
public class MenusController : Controller
{
readonly Services.ISecurityService _SecurityService;
public MenusController(Services.ISecurityService securityService)
{
_SecurityService = securityService;
}
[HttpGet(Contracts.ApiRoutes.Security.GetUserMenus)]
public IActionResult GetUserMenu(string userId)
{
string strUserMenus = _SecurityService.GetUserMenus(userId);
return Ok(strUserMenus);
}
[HttpPost(Contracts.ApiRoutes.Login.UserLogin)]
public IActionResult PostUserLogins([FromBody] Users user)
{ } public class MenusController : Controller { readonly Services.ISecurityService _SecurityService; public MenusController(Services.ISecurityService securityService) { _SecurityService = securityService; } [HttpGet(Contracts.ApiRoutes.Security.GetUserMenus)] public IActionResult GetUserMenu(string userId) { string strUserMenus = _SecurityService.GetUserMenus(userId); return Ok(strUserMenus); } [HttpPost(Contracts.ApiRoutes.Login.UserLogin)] public IActionResult PostUserLogins([FromBody] Users user) { }
my question why sending post request to function PostUserLogin on controller Authuntication Not working why ?
IMHO, your routing design is very confusing and overly complex. It was suggested in your duplicate thread to use standard routing. Why obfuscate the the route with a static property? There's no benefit unless the goal is to make your code hard to read.
Secondly, the login action is in the Menus Controller? Why? Just put the login in an Account Controller or Authentication Controller.
Again, your code is very very confusing. Unfortunately, like your other threads the shared code does not compile. Clearly the shared code is not the actual code that you are testing.
I built a simple test controller based in your code and it works just fine. I feel it is confusing to route authentication/login to the menus controller but this is your code and can be as confusing as you like.
public class MenusController : Controller
{
public IActionResult Index()
{
return Ok("Index");
}
//GET: Security/UserPrograms/{userId}
[HttpGet(Contracts.ApiRoutes.Security.GetUserMenus)]
public IActionResult GetUserMenu(string userId)
{
return Ok(userId);
}
//POST: Authuntication/login
[HttpPost(Contracts.ApiRoutes.Login.UserLogin)]
public IActionResult PostUserLogins([FromBody] Users user)
{
return Ok(user.Username);
}
}
public class Users
{
public string Username { get; set; }
}
Just be aware this design is very irritating because you force anyone trying to help you to read the code below to find the route. Why make your code so complex?
public class ApiRoutes
{
public const string SecurityBase = "Security";
public static class Security
{
public const string GetUserMenus = SecurityBase + "/UserPrograms/{userId}";
}
//Api url For Login
public const string SecurityLogin = "Authuntication";
public static class Login
{
public const string UserLogin = SecurityLogin + "/login";
}
}
Member
39 Points
362 Posts
Error 404 failed to load resources file when connect from post man to my app .net core 2.2
Sep 06, 2019 11:31 PM|ahmedbarbary|LINK
Problem
I have error 404 couldn't load resources when using post man to send post request to authunticationcontroller/PostUserLogin
I spend more time but in last not worked or not hit breakpoints on action PostUserLogin .
i move action PostUserLogin to controler MenuController and send post request by post man it worked and breakpoints hitted why this happen
what is wrong on my code
I need when put action PostUserLogin on Authunticationcontroller and send post request to authunticationcontroller/postuserlogin using post man breakpoint not hit .
when put break point on menu controller action PostUserLogin then press click button for send post request breakpoint hitted and it work
but when using another controller name Authuntication and put action PostUserLogin on it and i put breakpoints for test it is not sending post by post man why
and display error 404 why and hot to solve this problem
why authunticationcontroller/postuserlogin not working or breakpoint hit
public class ApiRoutes
{
public const string SecurityBase = "Security";
public static class Security
{
public const string GetUserMenus = SecurityBase + "/UserPrograms/{userId}";
}
//Api url For Login
public const string SecurityLogin = "Authuntication";
public static class Login
{
public const string UserLogin = SecurityLogin + "/login";
}
}
my question why sending post request to function PostUserLogin on controller Authuntication Not working why ?
All-Star
53091 Points
23659 Posts
Re: Error 404 failed to load resources file when connect from post man to my app .net core 2.2
Sep 07, 2019 12:14 PM|mgebhard|LINK
This is incorrect...
Remove "controller"
IMHO, your routing design is very confusing and overly complex. It was suggested in your duplicate thread to use standard routing. Why obfuscate the the route with a static property? There's no benefit unless the goal is to make your code hard to read.
Secondly, the login action is in the Menus Controller? Why? Just put the login in an Account Controller or Authentication Controller.
Member
39 Points
362 Posts
Re: Error 404 failed to load resources file when connect from post man to my app .net core 2.2
Sep 07, 2019 12:41 PM|ahmedbarbary|LINK
thank you for reply
i use Authuntication/login
it work on controller menu
and not work for controller Authuntication
why not work for controller authuntication
t
All-Star
53091 Points
23659 Posts
Re: Error 404 failed to load resources file when connect from post man to my app .net core 2.2
Sep 07, 2019 01:34 PM|mgebhard|LINK
Again, your code is very very confusing. Unfortunately, like your other threads the shared code does not compile. Clearly the shared code is not the actual code that you are testing.
I built a simple test controller based in your code and it works just fine. I feel it is confusing to route authentication/login to the menus controller but this is your code and can be as confusing as you like.
Just be aware this design is very irritating because you force anyone trying to help you to read the code below to find the route. Why make your code so complex?
Anyway, I configure the PostMan to POST to URL https://localhost:44327/Authuntication/login. With a body of...
.. and it just works.