2

I'm developing a Web API project and I need to deploy it on linux server. The requirements of the load balancer on the server is to have a default page.

For that reason I created a Home controller with Index action

[ApiVersion("1.0")]
[Route("/[controller]")]
public class HomeController : Controller
{
   [HttpGet("/")]
   [Route("Home/Index")]
   public IActionResult Index()
    {
            return View();
    }
}

Change the configure method in startup.cs

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
      {
         app.UseDeveloperExceptionPage();
      }

      app.UseDefaultFiles();
      app.UseStaticFiles();
      app.UseMvc();

}

Now after these changes if I deploy the app in local IIS it works fine and load the default View Home/Index when I access it the URL localhost:801

But If I deploy it on linux it gives a 503 error and there are different errors in the log too

Microsoft.AspNetCore.Routing.Tree.TreeRouter[1] Request successfully matched the route with name '(null)' and template ''.

Microsoft.AspNetCore.Mvc.Versioning.ApiVersionActionSelector[2] Action 'UMD.VAST.WebAPI.Controllers.HomeController.Index (UMD.VAST.WebAPI)' with id 'b83c6143-cd71-4847-90e8-14a963a8ce31' did not match the constraint

'Microsoft.AspNetCore.Mvc.Internal.HttpMethodActionConstraint' Microsoft.AspNetCore.Mvc.Internal.MvcAttributeRouteHandler[3] No actions matched the current request. Route values: Microsoft.AspNetCore.Builder.RouterMiddleware[1] Request did not match any routes. Microsoft.AspNetCore.Mvc.Routing.DefaultApiVersionRoutePolicy[5] Multiple candidate actions were found, but none matched the requested service API version '1.0'. Candidate actions: UMD.VAST.WebAPI.Controllers.HomeController.Index (UMD.VAST.WebAPI) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[0] An unhandled exception has occurred while executing the request System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(HttpRequest request) at Microsoft.AspNetCore.Mvc.Routing.DefaultApiVersionRoutePolicy.ClientError(RouteContext context, ActionSelectionResult selectionResult)

5
  • have you tried running running in vs with the production environment? also have you tried checking for errors in the console in the linux server? Commented Sep 18, 2017 at 3:55
  • It is working in release and debug mode from visual studio. and in Linux server it says : Request did not match any routes. Commented Sep 18, 2017 at 5:34
  • Not just release mode. You need to try in production environment as well. You can copy these existing profiles and create a new profile with "ASPNETCORE_ENVIRONMENT": "Production" Commented Sep 18, 2017 at 9:27
  • regarding the linux where are you seeing the error? not matching routes may also mean it is unable to reach the default error page location. Usually in production environment, it is designed to show the error page in the browser and the list of error logs in the console Commented Sep 18, 2017 at 9:36
  • change route to [Route("api/[controller]")] Commented Sep 21, 2017 at 6:34

1 Answer 1

1

I don't know why it doesn't work with Web API Controller, but I fixed it by using the MVC Controller for the Index page. Rest of the controller are Web Api controllers.

Code in Configure method for MVC routes is

 app.UseMvc(routes =>
  {
      //Home
      routes.MapRoute(
         name: "home",
         template: "{controller}/{action}/{id?}",
         defaults: new { controller = "Home", action = "Index" });
  });

For Web Api controllers I'm using the attribute routing

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.