The routing is default:
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
I have this piece of code that is inside of a Controller.
/// <summary>
/// Gets all the information for a specific username
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
[Route("GetUser/{userName}")]
[HttpGet]
public List<SomeList> GetUserObject(string userName)
{
Trace.WriteLine(userName);
Trace.WriteLine("HIT THIS <-----------");
return userName.getList();
}
I've renamed a few things that aren't relevant, but this is the exact setup.
Using Postman, if I send a request to this API at:
http://localhost:3040/api/SomeController/GetInformation/someemail@gmail.com
it will never hit the method, but if I remove the ".com" it will hit the method.
Why is it ignoring the ".com"?
Anything else will match except for adding the ".com" to it.
EDIT**
This doesn't quite work, I tried following the link listed but it doesn't quite work because I believe that link is MVC and what I'm working with is Web API, some routing and things are handled differently, I'm not quite able to map the differences.
this is in the Web.config
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="(userName/.*\..*[^/])$"/>
<action type="Rewrite" url="{GetUser}/"/>
</rule>
</rules>
</rewrite>
This is in the WebApiConfig.cs This is a new route I added above the default one
config.Routes.MapHttpRoute(
name: "GetUser",
routeTemplate: "api/{controller}/GetUser/{userName}/",
defaults: new
{
userName = RouteParameter.Optional
}
);
It doesn't work yet, what am I doing wrong?
Okay, this line fixed it:
<modules runAllManagedModulesForAllRequests="true"/> <!--Fix for IIS server trying to map to directories instead of URL when a '.' (period) is found in the route mapping.-->