Web Api帮助页面 - 重定向到MVC帮助页面

时间:2014-07-31 18:53:20

标签: c# asp.net-web-api asp.net-web-api-helppages

我在C#中创建了一个Web Api服务,并创建了一个帮助页面,其中添加了一个文件夹" Areas"与MVC项目。

我尝试将我的服务/帮助页面设置为我的默认页面,更改路由控制器,但当然,我无法做到这一点因为" help&#34 ;不是我的Web Api服务中的控制器。

当有人访问我的服务时,如何默认重定向到帮助页面?

谢谢和亲切的问候。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

相反,您可以将default.htm或Index.htm与Meta Refresh标记重定向到您的帮助。如果要在IIS中托管Web API,这将起作用。