Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "leoiii12"

using System.Reflection;
using System.Web.Http;
using Abp.Application.Services;
using Abp.Configuration.Startup;
using Abp.Modules;
using Abp.WebApi;
using Abp.WebApi.Controllers.Dynamic.Builders;

namespace UniTime.Api
{
    [DependsOn(typeof(AbpWebApiModule), typeof(UniTimeApplicationModule))]
    public class UniTimeWebApiModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes();
        }

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

            DynamicApiControllerBuilder
                .ForAll<IApplicationService>(typeof(UniTimeApplicationModule).Assembly, "app")
                .Build();

            Configuration.Modules.AbpWebApi().HttpConfiguration.Filters.Add(new HostAuthenticationFilter("Bearer"));
        }
    }
}

To prevent "Multiple actions were found that match the request", I put Configuration.Modules.AbpWebApi().HttpConfiguration.MapHttpAttributeRoutes(); inside the web api module.

[Route("api/Account/Register")]
        [HttpPost]
        [UnitOfWork]
        public async Task<AjaxResponse> Register(RegisterViewModel model)

        [Route("api/Account/Authenticate")]
        [HttpPost]
        public async Task<AjaxResponse> Authenticate(LoginModel loginModel)

However, it does not work. The error

{ "message": "An error has occurred.", "exceptionMessage": "Multiple actions were found that match the request: \r\nRegister on type UniTime.Api.Controllers.AccountController\r\nAuthenticate on type UniTime.Api.Controllers.AccountController", "exceptionType": "System.InvalidOperationException", "stackTrace": " at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)\r\n at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.GetDefaultActionDescriptor(HttpControllerContext controllerContext) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.Web.Api\WebApi\Controllers\Dynamic\Selectors\AbpApiControllerActionSelector.cs:line 107\r\n at Abp.WebApi.Controllers.Dynamic.Selectors.AbpApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.Web.Api\WebApi\Controllers\Dynamic\Selectors\AbpApiControllerActionSelector.cs:line 20\r\n at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.AccountControllerProxy_1.ExecuteAsync_callback(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at Castle.Proxies.Invocations.ApiController_ExecuteAsync.InvokeMethodOnTarget()\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Abp.Domain.Uow.UnitOfWorkInterceptor.Intercept(IInvocation invocation) in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 29\r\n at Castle.DynamicProxy.AbstractInvocation.Proceed()\r\n at Castle.Proxies.AccountControllerProxy_1.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()" }

still exist. Would anyone help me? :oops:

Showing 1 to 1 of 1 entries