1

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.-->
  • possible duplicate of [Dot character '.' in MVC Web API 2 for request such as api/people/STAFF.45287](http://stackoverflow.com/questions/20998816/dot-character-in-mvc-web-api-2-for-request-such-as-api-people-staff-45287) – Simon MᶜKenzie Aug 28 '15 at 01:31

1 Answers1

2

This issue is caused by the "." in your email address(which is someemail@gmail.com), the IIS will think you are looking for a file which name is someemail@gmail and it's type is com on server.

the solution is in this post https://stackoverflow.com/a/21000255/2077808

Community
  • 1
  • 1
Jeff Kong
  • 21
  • 4