Route属性在Microsoft.Azure.Mobile.Server中不起作用

时间:2016-01-10 19:25:01

标签: azure-mobile-services

我最近将后端项目从WindowsAzure.MobileServices.Backend更改为Microsoft.Azure.Mobile.Server。在新的'项目类型似乎在我的控制器方法上装饰的RouteAttribute不起作用。以下是配置的外观:

public partial class Startup
{
    public static void ConfigureMobile(IAppBuilder app)
    {
        var config = new HttpConfiguration();

        new MobileAppConfiguration()
            .UseDefaultConfiguration()
            .ApplyTo(config);

        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
        config.Formatters.JsonFormatter.SerializerSettings.DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Include;
        config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Include;
        config.MapHttpAttributeRoutes();

        var settings = config.GetMobileAppSettingsProvider().GetMobileAppSettings();

        if (string.IsNullOrEmpty(settings.HostName))
        {
            app.UseAppServiceAuthentication(new AppServiceAuthenticationOptions
            {
                SigningKey = ConfigurationManager.AppSettings["SigningKey"],
                ValidAudiences = new[] { ConfigurationManager.AppSettings["ValidAudience"] },
                ValidIssuers = new[] { ConfigurationManager.AppSettings["ValidIssuer"] },
                TokenHandler = config.GetAppServiceTokenHandler()
            });
        }

        app.UseWebApi(config);
    }
}

RouteAttribute再次正常工作需要什么?

1 个答案:

答案 0 :(得分:3)

我认为这是一个订购问题。在将MobileAppConfiguration应用于HttpConfiguration之前,应调用config.MappHttpAttributeRoutes()