简体   繁体   English

发布后路由不起作用

[英]Routing Doesn't Work After A Publish

I have a .NET 4.0 "Web Application" aka "Web Forms". 我有一个.NET 4.0“ Web应用程序”,又名“ Web表单”。 Inside this application I have a "Web API Controller Class", and my "Global.asax" 在此应用程序中,我有一个“ Web API控制器类”和我的“ Global.asax”

Inside Global.asax I have the following code in my "Application_Start" method. 在Global.asax内部,我的“ Application_Start”方法中包含以下代码。

var config = GlobalConfiguration.Configuration;

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

When I start a local debugging session, I can use my routes just fine. 当我启动本地调试会话时,可以使用我的路由。 If I type in "/api/ZipCodes", I get my expected JSON response. 如果输入“ / api / ZipCodes”,则会得到预期的JSON响应。

When I publish my project, to my remote IIS server (publish method: File System) the route no longer works. 当我将项目发布到远程IIS服务器(发布方法:文件系统)时,路由不再起作用。 I get a 404 error. 我收到404错误。

I am assuming there is a setting or something I need to enable on IIS in order for it to recognize and use routes. 我假设我需要在IIS上启用某个设置或某些功能,以使其能够识别和使用路由。

  • IIS version 7.0.6000.16386 IIS版本7.0.6000.16386
  • .NET Application Pool version 4.0 .NET应用程序池版本4.0

  • My website resides in "C:\\inetpub\\hosts" along with 7+ other websites that all work. 我的网站与其他7个以上都能正常运行的网站位于“ C:\\ inetpub \\ hosts”中。 None use routing. 没有人使用路由。

  • I have a Default.aspx with "Hello World", and I can access that correctly on the remote IIS server and on my local debug session. 我有一个带有“ Hello World”的Default.aspx,可以在远程IIS服务器和本地调试会话上正确访问它。
  • When I debug on my local machine, I can enter "http://localhost:6358/api/ZipCodes" and get my JSON response. 在本地计算机上调试时,可以输入“ http:// localhost:6358 / api / ZipCodes”并获取JSON响应。 If I enter the same url on my remote machine "http://remoteserver.com/api/ZipCodes", it gives me a 404. 如果我在远程计算机“ http://remoteserver.com/api/ZipCodes”上输入相同的URL,它将显示404。

Anyone have any idea? 有人知道吗

Do you have your home folder set correctly? 您的主文件夹设置正确吗? Because that's what happened to me today. 因为那就是我今天发生的事情。 It should point to the root folder of the application, not the root of the server. 它应该指向应用程序的根文件夹,而不是服务器的根目录。

EDIT: Could you give us the folder you published your application to? 编辑:您能给我们您将应用程序发布到的文件夹吗?

Also, if you want to know how to setup the "Home Folder" (The folder the server points to when a request is made to ie: www.yoursite.com) take a look at this link: https://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/a59a2665-9078-43ef-8b5a-5bf9bcacc95e.mspx?mfr=true 另外,如果您想知道如何设置“主文件夹” (当服务器发送请求时服务器指向的文件夹,即:www.yoursite.com),请查看以下链接: https : //www.microsoft .com / technet / prodtechnol / WindowsServer2003 / Library / IIS / a59a2665-9078-43ef-8b5a-5bf9bcacc95e.mspx?mfr = true

TO SUM UP: 总结一下:

You'll have to setup your "Home Folder" to point to the application's folder , or put your application files to the preset folder (think it's named something like this: LocalDrive:\\Inetpub\\Wwwroot ) 您必须设置“主文件夹”以指向应用程序的文件夹 ,或将您的应用程序文件放到预设的文件夹中 (认为​​它的名称如下: LocalDrive:\\ Inetpub \\ Wwwroot

如果您的IIS是最新的(我假设是7.0或更高版本),并且将应用程序池配置为用户框架4.0,则应该可以使用任何其他操作或配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM