对控制器的调用被解释为对静态文件的请求 [英] calls to controller are interpreted as requests to static files
问题描述
我有一个在localhost上运行正常的网络应用程序。当我部署到Azure时,对控制器的调用被解释为对静态文件的请求,而我找不到404。看起来如下:
请求的URL协议然后< webAppName> / Home /添加
发送至:
物理路径D:\\\\\\\\\\\\\\\ \ www.root \Home \添加
I have a web app that works fine on localhost. When I deploy to Azure, calls to controller are interpreted as requests to static files and I get a 404 not found. It looks like that:
Requested URL protocol then <webAppName> /Home/Add
is sent to:
Physical Path D:\home\site\wwwroot\Home\Add
(很抱歉格式不佳,但不会让我发布链接)
(Sorry for the poor formatting but it won't let me post links)
任何帮助表示感谢!
编辑:
我不喜欢有一个global.asax文件
I don't have a global.asax file
路由应该在Startup.cs中完成,我有以下内容:
Routing should be done in Startup.cs, I have the following:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
在HomeController.cs中:
In HomeController.cs:
[Route("methodName")]
public ActionResult MethodName()
{
//do stuff
}
我在网络服务器上没有任何错误l og流媒体服务。我只有404申请日志。
I don't have any error in the web server log streaming service. I only have a 404 in application log.
我试图删除[Route("")]属性,但错误保持不变。
I tried to remove the [Route("")] attribute but the error stays the same.
我试图通过https和http调用但同样的错误。
I tried to call over https and http but same error.
我在天蓝色网站上启用了HTTPS但是同样的错误。
I enabled HTTPS on the azure portal but same error.
我尝试从我的页面和浏览器(chrome)发送请求,但同样的错误。
I tried to send the request from my page and from the browser (chrome) but same error.
在控制器的开头添加了[AllowAnonymous],但错误相同。
Added [AllowAnonymous] at the start of the controller but same error.
已添加[HttpPost ]就在方法声明之前,同样的错误。
Added [HttpPost] just before the method declaration, same error.
推荐答案
感谢您提出问题!您可以尝试在Startup.Configure中调用UseStaticFiles方法。
public void配置(IApplicationBuilder app)
{
&NBSP; app.UseStaticFiles();
}
您可以参考下面的文档可能会有帮助。
Thanks for asking the question! You can try to Invoke the UseStaticFiles method within Startup.Configure
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
}
You may refer below document might be helpful.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals /static-files?view=aspnetcore-2.2
这篇关于对控制器的调用被解释为对静态文件的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!