I have a Web API endpoint that accepts a GET request with two parameters.
[AllowAnonymous]
[Route("user/{username}/{password}")]
[HttpGet]
public async Task<IHttpActionResult> GetUser(string username, string password)
{
// Lookup user
var user = await this.AppUserManager.FindAsync(username, password);
if (user != null)
{
return Ok(this.TheModelFactory.Create(user));
}
return Content(HttpStatusCode.NotFound, "User not found");
}
This method works fine except in cases where the password ends in a period (.). In these cases I get the following error Server Error in '/' Application.
. I ended up changing the method to POST and passed the UserName and Password in the body. Why is a trailing period crashing the API? I would have preferred to use GET as I felt it was more appropriate.
I tried the suggestion in this SO posting but still no luck.
<system.webServer>
....
<rewrite>
<rules>
<rule name="Add trailing slash" stopProcessing="true">
<match url="^(api/employees/.*\.[a-z]{2,4})$" />
<action type="Rewrite" url="{R:1}/" />
</rule>
</rules>
</rewrite>
</system.webServer>