Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michael Pedersen 3 posts 75 karma points
    Oct 30, 2020 @ 08:26
    Michael Pedersen
    0

    Custom Route Name causing Umbraco to fail

    Hi everyone, I have stumbled upon a weird scenario using custom routes. I have created an attribute route component

    public class AttributeRoutingComponent : IComponent
    {
        public void Initialize()
        {
            GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
        }
    
        public void Terminate()
        {
        }
    }
    

    Which is added in my bootstrapper

    public void Compose(Composition composition)
        {
            DependencyInjectionConfiguration.SetupDependencyInjection(composition);
            composition.Components().Append<AttributeRoutingComponent>();}
    

    I have several routes which are all working just fine. I have one route which creates content in a seperate database. I wanted to return the route at which this content can be retrieved using the "CreatedAtRoute", this means that my get route needs to have a route name. As soon as I add the "Name" part of the route, Umbraco CMS throws a hissyfit and won't start. My APIs work just fine through postman, but Umbraco CMS, not so much.

    [Route("applicationTypes/{applicationTypeId}/applications")]
        [HttpPost]
        public async Task<IHttpActionResult> AddApplication([FromUri] Guid applicationTypeId, [FromBody] dynamic json)
        {
            var responseId = await _databaseService.AddApplication(applicationTypeId, json);
            return CreatedAtRoute("GetApplicationById", new { applicationTypeId, applicationId = responseId }, "Application successfully added");
        }
       [Route("applicationTypes/{applicationTypeId}/applications/{applicationId}", Name = "GetApplicationById")]
        [HttpGet]
        public async Task<IHttpActionResult> GetApplication([FromUri] Guid applicationTypeId, int applicationId)
        {
            var application = await _databaseService.GetApplication(applicationId);
            return Ok(application);
        }
    

    If I name my route the GetApplicationById as above I clearly get an error stating that that name is already taken. But if I name it something random I get a weird error, that doesn't really tell me much

    enter image description here Does anyone have an idea?

Please Sign in or register to post replies

Write your reply to:

Draft