0

Hi. Is this possible to separate URL parameters for two placeholder {Name} and {Surname} like below ?

 routes.MapRoute( name: "Users", url: "Authorization/{Name}.{Surname}", defaults: new { controller = "Authorization", action = "Verify" } ); 

And in my action method use following code :

private bool Verify (string Name,string Surname) { [...] } 

Or do I have to use one placeholder and parse my string to extract information :

 routes.MapRoute( name: "Users", url: "Authorization/{UserName}", defaults: new { controller = "Authorization", action = "Verify" } ); 

And in Action method use following code :

private bool Verify(string UserName) { string name = "UserNameTillDot"; string surname = "UserNameAfterDot"; [...] } 
4
  • Have you tried the first approach, or are you asking us before you've tried it? Commented Dec 21, 2014 at 17:46
  • Yes. I have tried and result is 404 Error Commented Dec 21, 2014 at 17:48
  • Url should follow some principles, so what you should rather try is url: "Authorization/{Name}/{Surname}" Commented Dec 21, 2014 at 17:50
  • But what I would like to achieve is to enable URL in this format website/name.surname by first solution. Commented Dec 21, 2014 at 17:52

1 Answer 1

1

The first approach is totally fine. The problem is that your action in controller is defined as private:

Instead of

private bool Verify (string Name, string Surname) { [...] } 

It should be

public ActionResult Verify (string Name,string Surname) { [...] } 

Also if you want to allow null for Name or Surname you should make them optional:

 routes.MapRoute( name: "Users", url: "Authorization/{Name}-{Surname}", defaults: new { controller = "Authorization", action = "Verify", Name = UrlParameter.Optional, Surname = UrlParameter.Optional } ); 

You also should place this route before your default route.

EDIT: There is a issue with "." in the route you can replace it with "-"

Sign up to request clarification or add additional context in comments.

2 Comments

The problem is with '.' in URL string . ASP NET MVC threat it as path to file .
So replace the "." with "-" and it will solve the issue

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.