0

I have a rather archaic login system, and this is part of the login action:

// login action
return RedirectToAction("Action", new {
  id = aVal,
  name = aName,
  // other params
});

It redirects the user to the Action action, and i noticed that name and the other params ended up being part of the final url scheme. I need to pass all those values to Action.

[HttpGet]
public ActionResult Action(int id, string name, ...) {
  1. Is it possible to pass them to Action and having the url like this: /Controller/Action/123.
  2. I need to restrict the Action method to only those who pass through the login action, the long url + query string make it almost impossible to make it through, but is there another more profesional way to do it.

Thanks and greetings to the SO and SE community.

1 Answer 1

1

In order to get Restful styled url's you need to setup an appropriate route.

So in your case something like

routes.MapRoute("MyRoute", "MyController/MyAction/{id}/{name}", new { controller = "MyController", action = "MyAction" });

you can see some other examples here

The second part of your question is more vague - you may want to tag your class with an [Authorize] attribute and then override OnAuthorization where you can do any checks. Not sure if this is what you are looking for.

There is an example of this here

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.