【发布时间】:2014-05-28 09:01:38
【问题描述】:
我创建了我的第一个 owin/web.api REST 服务。 一些超级简单的东西,只是为了测试一些功能。
我使用 Visual Studio 2013 创建了一个空项目并安装了以下软件包:
- Microsoft.AspNet.WebApi.Client
- Microsoft.AspNet.WebApi.Core
- Microsoft.AspNet.WebApi.Owin
- Microsoft.Owin
- Microsoft.Owin.Diagnostics
- Microsoft.Owin.Host.SystemWeb
- Newtonsoft.Json
- 欧文
这是我的启动课:
[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();
}
}
}
这是我的 Api 控制器:
[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 });
}
}
我的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>
没什么太复杂的。
问题:
此 Web.Api 服务适用于任何地方。
我已经在我的 PC 上使用 IIS Express (8.0) 和我的 IIS 7.5 (Windows 7) 对其进行了测试。 我已经将它部署到我的托管服务提供商 (Arvixe) 并且它可以工作。 我已将它部署在服务器(Windows 2008 Server R2)上,它可以工作。
它在应该起作用的地方不起作用的问题。
我的客户服务器是带有 IIS 7 的 Windows 2008 sp2(32 位)。
我已成功启动 Owin,但无法路由请求。
我无法访问地址:[server ip]/api/v1/test
我的尝试:
我已经检查了服务器的配置:
- 框架 4.5.1 已安装。
- IIS 已启动并正在运行(我已安装其他 ASP.NET MVC Web 应用程序)
我已尝试删除自定义路由前缀:
[RoutePrefix("api/v1")]
我检查了 IIS 日志并且请求到达 IIS。 就是不知道怎么路由。
为了交叉检查问题,我创建了一个没有 Owin 的简单 web.api(具有相同的路由系统)并且它可以工作。
同样的 Owin 应用自托管作品。
【问题讨论】:
-
你是如何解决这个问题的?看起来我在这里遇到了完全相同的问题,不知道该怎么办......
-
@ultraman69:我现在已经回答了我自己的问题。我想没有办法解决这个问题。我已升级到新的 IIS,一切正常。
标签: iis-7 asp.net-web-api owin