Base solution for your next web application
Open Closed

Attribute routing in webapi is not working #1005


User avatar
0
jawadsharif created

tried to enable HTTP attribute routing in API module configuration but after that I get exception at application start. please check attached image.

public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

        //Automatically creates Web API controllers for all application services of the application
        DynamicApiControllerBuilder
            .ForAll<IApplicationService>(typeof(SpeedApplicationModule).Assembly, "app")
            .Build();

        <span style="color:#FF0000">Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes();</span>
        Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));

        ConfigureSwaggerUi(); //Remove this line to disable swagger UI.
    }


2 Answer(s)
  • User Avatar
    0
    jawadsharif created

    i Have figured out the issue after a bit of searching

    moving following line in PreInitialize() method before ConfigureOData method call will solve the issue

    Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes();

    the issue was due to the sequence of httpConfiguration calls OData config was called before it

  • User Avatar
    0
    jawadsharif created

    I Recomment to enable attribute routing by default