我有一个Web Api应用程序.当我使用VS 2010调试开发服务器测试它时,它运行得非常好.但我现在将其部署到IIS 7.5,并在尝试访问应用程序时收到HTTP 404错误.
这是我的web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-FlowGearProxy-20123141219;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="true" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" …Run Code Online (Sandbox Code Playgroud) 关闭我部署的几乎每个网站/ api服务/移动服务,当我点击除默认路由之外的任何路由时,我收到以下错误"您正在寻找的资源已被删除,其名称已更改,或暂时不可用."
为了测试,我创建了一个简单的ASP.Net WebAPI应用程序和ASP.Net MVC网站并部署到Azure.它被部署并出现默认页面.对于之后的任何链接,我都会收到该错误.
以下是移动服务..未经修改即创建和上传,并在portal.azure.com上配置了facebook身份验证https://wayweb.azurewebsites.net/.auth/login/facebook/callback
代码复制件位于https://1drv.ms/u/s!AkQ9G9AdaYOPgaZ-vXUdlSW9RuQzOQ
任何想法,我做错了什么?
第一条路线有效.
例如 api/Shelves/SpaceTypes/1
第二条路线不起作用.我得到多个动作错误.
例如 api/Shelves/1
问)为什么?
这些是我的路线:
config.Routes.MapHttpRoute(
"DefaultApiWithAction",
"api/{controller}/{action}/{id}"
);
config.Routes.MapHttpRoute(
"DefaultApiWithId",
"api/{controller}/{id}",
null,
new { id = @"\d+" }
);
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
public HttpResponseMessage Get(int id)
{
...
}
[ActionName("SpaceTypes")]
public HttpResponseMessage GetSpaceTypes(int id)
{
...
}
Run Code Online (Sandbox Code Playgroud) 我一直严格遵循此链接(https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.2&tabs=visual-studio)来创建我的Web api 。
**在本地,它运行良好。测试了链接并返回 JSON 数据
但是,一旦我将 Web api 部署到 azure 应用程序服务,我的所有 api 链接都会返回错误 404。是否有任何我可能错过的路由?
在我的控制器中,我已将其添加到我的头脑中。
[Route("api/xxx")]
[ApiController]
Run Code Online (Sandbox Code Playgroud)
在每个函数中,我都添加了这个
[HttpPut("xxx/{Id}")]
Run Code Online (Sandbox Code Playgroud)
至于我的程序/启动它与教程完全相同
节目类
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Run Code Online (Sandbox Code Playgroud)启动.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts(); …Run Code Online (Sandbox Code Playgroud)asp.net azure asp.net-web-api asp.net-web-api-routing asp.net-core-2.1