1

I have set the routing api/Exchange/Groups/Members/{samAccountName} on my web api and is working

But if the value of samAccountName contains wording "prn.", It will return The resource cannot be found.

Example

http://localhost:4483/api/Exchange/Groups/Members/prn.agency1

http://localhost:4483/api/Exchange/Groups/Members/prn.agency2

http://localhost:4483/api/Exchange/Groups/Members/prn.agency3

I not sure where is wrong. Here is my code snippet

[HttpGet]
[Route("api/Exchange/Groups/Members/{samAccountName}")]
public HttpResponseMessage GetMembers(string samAccountName)
{
   //Query from Exchange       
}

Any idea?

Azri Zakaria
  • 1,324
  • 5
  • 23
  • 52
  • Duplicate question see https://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287 – Alfredo A. Oct 23 '18 at 18:21

2 Answers2

0

The problem is in your samAccountName format - it contains dot, which is interpreted by IIS as a file extension. IIS tries to find handler for file type *.agency1 (agency2, agency3), cannot find it and throws an error.

You either should change format to exclude dot, like change it to dash/underscore, or enable this parameter in your web.config

<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />

Some more information and drawbacks about runAllManagedModulesForAllRequests flag can be found in this blog post: https://weblog.west-wind.com/posts/2012/Oct/25/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78

Pavel Morshenyuk
  • 10,891
  • 4
  • 32
  • 38
0

In web.config, add

<system.web>
   <httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>

More details explained here.

Mike
  • 721
  • 7
  • 13