在Web表单ASP.NET网页API [英] ASP.NET Web Api in Web forms
问题描述
我正尝试使用Web表单的asp.net网页API与Visual Studio 2010(SP1)
我这样做的步骤<一个href=\"http://myrandomykien.blogspot.com/2012/02/simplest-web-api-site-with-nuget.html\">http://myrandomykien.blogspot.com/2012/02/simplest-web-api-site-with-nuget.html
当我使用Visual Studio开发服务器的它的工作原理,但在使用IIS 7.5 i'm我得到一个HTTP错误404.0 - 未找到
修改
这是我的全局ASAX
保护无效的Application_Start(对象发件人,EventArgs的发送)
{
RouteTable.Routes.MapHttpRoute(
名称:DefaultApi
routeTemplate:API / {}控制器/(编号),
默认:新{ID = System.Web.Http.RouteParameter.Optional}
);
}
这是API类
公共类GreetingController:ApiController
{
公共字符串GetGreeting(字符串ID)
{
返回的String.Format(你好{0},身份证);
}
}
您必须确保无扩展名的请求路由到ASP.NET是默认你的开发服务器,但没有做IIS。
有几个可能的方法。
首先,你可以在的 system.webServer
模块部分添加 runAllManagedModulesForAllRequests =真正的
。有些人声称有更好的方法,你就可以跟着他们:
<一个href=\"http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html\">http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
i´m trying to use the asp.net web api in WEB FORMS with visual studio 2010 (sp1) i have done this steps http://myrandomykien.blogspot.com/2012/02/simplest-web-api-site-with-nuget.html
When i use the visual studio development server it works, but when i´m using iis 7.5 i get an Error HTTP 404.0 - Not Found.
Edit
This is my Global-asax
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
}
This is the api class
public class GreetingController : ApiController
{
public string GetGreeting(string id)
{
return String.Format("Hello {0}", id);
}
}
You have to make sure that extensionless requests are routed to ASP.NET which is done by default by your development server but not IIS.
There are couple of possible approaches.
First, you could add runAllManagedModulesForAllRequests="true"
in the modules section of the system.webServer
. Some people claim there are better methods, you can then follow them:
http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html
这篇关于在Web表单ASP.NET网页API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!