Search code examples
c#asp.net-web-apiasp.net-web-api-helppages

Web Api Help Page - Redirect to MVC help page


I've a Web Api Service in C# and I created a Help Page, that added a folder "Areas" with a MVC project.

I tried to make my SERVICE/help page into my default page, changing the controller on the routing but of course, I couldn't do it because "help" is not a controller in my Web Api Service.

How can I redirect to the help page by default when someone acess to my service?

Thanks and kind regards.


Solution

  • public class IndexController : ApiController
    {
        [AllowAnonymous]
        [Route("")]
        public HttpResponseMessage GetIndex()
        {
            var response = Request.CreateResponse(HttpStatusCode.Moved);
            string fullyQualifiedUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority);
            response.Headers.Location = new Uri(fullyQualifiedUrl + "/help");
            return response;
        }
    }