webapi MVC - Return HomePage when create WebApi Empty

时间:2017-04-06 16:46:53

标签: asp.net-mvc asp.net-web-api

I've created an empty webapi project and I would like to add a homepage View. For some reason, it does not work - it always returns authorization access deny, but I've set the attribute [AllowAnonymous] on HomeController.

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

[AllowAnonymous]
public class HomeController : Controller
{  
    [HttpGet]
    public ActionResult Index()
    {
        return View();
    }
}

Can anyone help with this issue please? Thanks

0 个答案:

没有答案