Try our conversational search powered by Generative AI!

How to use web api attribute routingg

Vote:
 

Is there any way to use attribute routing in an EPiServer 7.5 MVC site?
I tried to set this in the WebApiConfig class

    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
        }
    }

    and i have this in the global.asax.

        protected void Application_Start()
        {
            // Register Display Options
            var options = ServiceLocator.Current.GetInstance<DisplayOptions>();
            options
                .Add("full", "/displayoptions/full", ContentAreaTags.FullWidth, "", "epi-icon__layout--full")
                .Add("wide", "/displayoptions/wide", ContentAreaTags.TwoThirdsWidth, "", "epi-icon__layout--two-thirds")
                .Add("narrow", "/displayoptions/narrow", ContentAreaTags.OneThirdWidth, "", "epi-icon__layout--one-third");

            GlobalConfiguration.Configure(WebApiConfig.Register);
            AreaRegistration.RegisterAllAreas();
        }

    This is a sample api controller I use.

namespace EPiServer.Templates.Alloy.Controllers.Api
{
    public class PageInfo : ApiController
    {
        // GET api/<controller>
        [Route("api/infopage")]
        [HttpGet]
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
}


Any help would be much appreciated.
#81887
Feb 28, 2014 3:27
Vote:
 

Sure, this should be possible. I used Web API 2.0 in this blog post about creating an auto suggest property: http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2013/12/Auto-suggest-editor-in-EPiServer-75/

#81889
Feb 28, 2014 7:28
Vote:
 

Can it be for HttpPost ?

#298437
Mar 16, 2023 20:45
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.