I don't have an answer to your issue, all I can say is that I'm using Umbraco 7.5.13. I haven't added/installed or changed any membership providers.
I have installed Swagger (technically its Swashbuckle) into my Umbraco instance, so that I can test and document the End Points, which I show a screenshot here.
The code being used to generate those end points is in essence the code I posted in my previous post. And everything works as advertised.
@Ivan Is it possible to do dependency injection for APIcontrollers, because i need to inject another service of umbraco during api call, for example IMemberService, i have tried with light inject and auto fac nut nothing worked, please check the error below,
(Question related to umbraco 8)
{
"Message": "An error has occurred.",
"ExceptionMessage": "An error occurred when trying to create a controller of type 'MyController'. Make sure that the controller has a parameterless public constructor.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": " at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Type 'Integration.Controllers.MyController' does not have a default constructor",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.Linq.Expressions.Expression.New(Type type)\r\n at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"
}
I have resolved the issue by using UmbracoApiController and i have registerd my services using IUserComposer so dependency injection works fine as expected. after all, UmbracoApiController is inheriting System.Web.Http.ApiController, so it is working fine as expected.
Can I use Rout Attributes in Umbraco controllers?
Hi guys!
The controller is as follows:
I can easily access the method like this:
But can I do the same with:
I know it’s possible in ASP.NET Web API 2.0 using Rout Attributes. Not sure about Umbraco however.
Hi Ivan,
You sure can, I do it myself all the time.
https://docs.microsoft.com/en-us/aspnet/web-api/overview/web-api-routing-and-actions/attribute-routing-in-web-api-2
Cheers
Jonathan
I'm trying something similar, but with an UmbracoAuthorizedController:
But I get a 404 when I try to go to /umbraco/backoffice/MyDashboardSection
Any reason on why that wouldn't work?
Turns out I needed to add /api/ in there. I guess it must be a route restriction within Umbraco.
So my new controller now looks like:
Hi Jonathan,
Thanks for your effort. But I couldn't get this working.
When I access the
Umbraco is not able to route this correctly and always returns 404.
But this url is handler correctly:
event though I use routing attributes just as you showed in previous post.
Which version of Umbraco are using? We use Umbraco 7.5.8 along with OWIN.
Hi Ivan,
I don't have an answer to your issue, all I can say is that I'm using Umbraco 7.5.13. I haven't added/installed or changed any membership providers.
I have installed Swagger (technically its Swashbuckle) into my Umbraco instance, so that I can test and document the End Points, which I show a screenshot here.
The code being used to generate those end points is in essence the code I posted in my previous post. And everything works as advertised.
Cheers
Jonathan
Hi Ivan,
I think the RoutePrefix starts from the root, so you probably want to add umbraco in there as well to make it work on the URL you're trying:
Hi Tom,
That did not help, unfortunately. I installed UmbracoCMS 7.5.13 on top of empty ASP.NET Web solution, and created simple controller:
But result remains same:
I assume you did remember to include a call to
RouteTable.Routes.MapMvcAttributeRoutes()
(link) somewhere in your application start events?Thanks, Tom! Cannot believe I made this working.
It turned out:
For those who faced similar problem, I'm posting final solution:
UmbracoApplicationEventHandler.cs
WebApiConfig.cs
ProductsController.cs:
Yes, that has happened to me once as well. It's frustrating once you realise why it isn't working :-)
Thanks for this pointer. In case someone has the same problem as me. For me the issue was:
using System.Web.Mvc;
Instead of:
using System.Web.Http;
(the .Mvc namespace was referenced to my controller before I added custom routes, so the [RoutePrefix] didn't give any errors.
@Ivan Is it possible to do dependency injection for APIcontrollers, because i need to inject another service of umbraco during api call, for example IMemberService, i have tried with light inject and auto fac nut nothing worked, please check the error below, (Question related to umbraco 8)
}
I have resolved the issue by using UmbracoApiController and i have registerd my services using IUserComposer so dependency injection works fine as expected. after all, UmbracoApiController is inheriting System.Web.Http.ApiController, so it is working fine as expected.
is working on a reply...