0

I am having difficulties defining login and register routes without a controller prefix. I have a user controller that has the methods for "Login(String email, String password)" and "Register(User user)".

The format I want to achieve is "api/login" and "api/register".

I tried the following code for login:

config.Routes.MapHttpRoute(
      name: "Login",
      routeTemplate: "api/login",
      defaults: new { controller = "Users", action = "Login" });

However, I get this error:

{
    "Message": "No HTTP resource was found that matches the request URI 'http://localhost:50145/api/login/'.",
    "MessageDetail": "No type was found that matches the controller named 'login'."
}

1 Answer 1

0

It turned out that with attribute routing and the tilde sign it is possible to overwrite prefixes

[Route("~/api/login")]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.