2
votes

I've created my first owin/web.api REST service. Something super simple just to test some features.

I've created an empty project with Visual Studio 2013 and installed a these packages:

  • Microsoft.AspNet.WebApi.Client
  • Microsoft.AspNet.WebApi.Core
  • Microsoft.AspNet.WebApi.Owin
  • Microsoft.Owin
  • Microsoft.Owin.Diagnostics
  • Microsoft.Owin.Host.SystemWeb
  • Newtonsoft.Json
  • Owin

This is my startup class:

[assembly: OwinStartup(typeof(OwinO.Startup))]
namespace OwinO
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
        HttpConfiguration config = new HttpConfiguration();

        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
            );

        app.UseWebApi(config);

        app.UseWelcomePage("/");
        app.UseErrorPage();
        }
   }
}

and this is my Api Controller:

[RoutePrefix("api/v1")]
public class TestController : ApiController
{
    [HttpGet]
    [Route("test")]
    public async Task<IHttpActionResult> Get()
    {
        string name = "Mister";
        string sayHello = string.Empty;

        Task<string> t = new Task<string>(() =>
        {
            sayHello = string.Format("Hello {0}", name);
            return sayHello;
        });
        t.Start();
        await t;

        return Ok(new string[] { sayHello });
    }
}

My Web.Config:

<system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
</system.web>

<system.webServer>
  <!--<modules runAllManagedModulesForAllRequests="true" />-->
    <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

Nothing really too complicated.

PROBLEM:

This Web.Api service works everywhere.

I've tested it on my PC with IIS Express (8.0) and my IIS 7.5 (Windows 7). I've deployed it to my hosting provider (Arvixe) and it works. I've deployed it on a server (Windows 2008 Server R2) and it works.

The problem it does not work where it should work.

My client's server is Windows 2008 sp2 (32 bit) with IIS 7.

I've managed to startup Owin but requests cannot be routed.

I cannot access the address: [server ip]/api/v1/test

WHAT I'VE TRIED:

I've checked the server's configuration:

  • Framework 4.5.1 is installed.
  • IIS is up and running (I've got other ASP.NET MVC web apps installed)

I've tried to remove the custom routing prefix:

[RoutePrefix("api/v1")]

I've checked the IIS log and the requests reach IIS. It's just it does not know how to route.

To cross-check the problem I've created a simple web.api without Owin (with the same routing system) and it works.

The same Owin app self-hosted works.

1
How did you fix this issue ? Looks like I have the exact same problem here and have no clue what to do...Patrice Cote
@ultraman69: I've answer my own question now. There is no way to fix this, I guess. I've upgraded to a new IIS and everything worked as expected.LeftyX

1 Answers

0
votes

There is not fix for this.

I've spent a good amount of time trying to find a solution or a way to fix it. After the server upgrade everything worked as expected.