0

我已经为我的应用程序创建了一个 asp webapi 来连接数据库。在本地主机上开发时一切正常。但是在发布之后,除了主页之外什么都没有。发布后我的路由似乎不起作用

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "sd/{controller}/{action}"
        );

        routes.MapHttpRoute(
            name: "ParamApi",
            routeTemplate: "sd/{controller}/{action}/{param}",
            defaults: new { param = RouteParameter.Optional }
        );

        routes.MapHttpRoute(
            name: "GuestApi",
            routeTemplate: "sd/{controller}/{action}/{username}/{password}/",
            defaults: new
            {
                username = UrlParameter.Optional,
                password = UrlParameter.Optional
            }
        );

        routes.MapHttpRoute(
            name: "BriefcasePutApi",
            routeTemplate: "sd/{controller}/{action}/{id}/{value}/{owner}",
            defaults: new { 
                id = RouteParameter.Optional,
                value = RouteParameter.Optional,
                owner = RouteParameter.Optional
            }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

发布后唯一起作用的是带有 name 的路由Default。其余的都不是。我收到这样的错误:

Server Error in '/' Application.

Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.\r\n

 Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".`

当我调用 url 时出现此错误:http://domain.com/sd/content/get

在我的本地主机上它工作得很好,但在发布后不能在天蓝色上

我可能错了,这是路由问题,但我不知道还能去哪里看。

我在 .NET 4.5 中创建了项目,但之后我发现我还不能在 azure 上使用它,所以我将它转换为 4.0

更新 好的。与控制器快速检查后,我得到空白页。没有错误:/

检查是我的操作返回整数“2”。所以我知道这个问题不是由一些正在运行的代码引起的。但是现在我没有错误,什么也没有。只是空白页

奇怪的事情:Firefox 返回空白页面,但 Internet Explorer 返回错误 500


在下面回答

4

1 回答 1

1

我发现了问题!

我已经从 .NET 4.5 回滚到 .NET 4.0,但 Entity Framework 没有从 5.0 回滚到 4.3.1,所以我必须手动卸载 v 5.0,然后从 NuGet 安装 4.3.1。之后一切开始工作!

于 2012-10-16T09:45:48.363 回答