Question

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.

Was it helpful?

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;
    }
}

OTHER TIPS

Rather You could have default.htm or Index.htm with Meta Refresh tag which redirects to your help. This will work if Web API to be hosted in IIS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top