title: Asp.net MVC Web API Call Redirect to Accountcontroller Login
body: <p>My code is</p>
  
  <p><strong>RouteConfig:</strong></p>
  
  <pre><code>    public static void RegisterRoutes(RouteCollection routes)
      {
          routes.MapRoute(
              name: "Default",
              url: "{controller}/{action}/{id}",
              defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
          );
      }
  </code></pre>
  
  <p><strong>WebAPIConfig:</strong></p>
  
  <pre><code>    public static void Register(HttpConfiguration config)
      {
          config.MapHttpAttributeRoutes();
  
          config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
  
          config.Formatters.Clear();
          config.Formatters.Add(new JsonMediaTypeFormatter());
      }
  </code></pre>
  
  <p><strong>WebAPI Controller:</strong></p>
  
  <pre><code>public class ServicesController : ApiController
  {
      public string Get()
      {
          return "Hello World";
      }
  
  }
  </code></pre>
  
  <p><strong>AccountCtonroller:</strong></p>
  
  <pre><code>    public ActionResult Login(string returnUrl)
      {
          // User Login functionality
          ViewBag.ReturnUrl = returnUrl;
  
          return View();
      }
  </code></pre>
  
  <p>Global.asax.cs</p>
  
  <pre><code>   protected void Application_Start()
      {                     
          GlobalConfiguration.Configure(WebApiConfig.Register);            
          AreaRegistration.RegisterAllAreas();
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
  </code></pre>
  
  <p>Issue I am facing here is:
  1. when i invoke Webapi <a href="http://localhost/myapplication/api/services" rel="nofollow">http://localhost/myapplication/api/services</a> in browser, it redirect to</p>
  
  <p><a href="http://localhost/myapplication/Account/Login?ReturnUrl=%myapplication%2Fapi%2Fservices" rel="nofollow">http://localhost/myapplication/Account/Login?ReturnUrl=%myapplication%2Fapi%2Fservices</a></p>
  
  <p>Any thoughts on this?</p>
  
  <p>Thanks,</p>