-1

Using .NET Core 3.1, I developed a MVC app and deployed it on IIS 8.5.

Using the browser, I am able to go to the home page when I visit domain.com/myApp/ but I get a http 500 error when I go domain.com/myApp. This is working locally. The issue occurs on the deployed server.

Here is the routing I have in Startup.cs

app.UseEndpoints(endpoints =>
{
    // localization
    endpoints.MapControllerRoute(
        name: "LocalizedDefault",
        pattern: "{language:language}/{controller}/{action}/{id?}");

        endpoints.MapControllerRoute(
        name: "default",
        pattern: "{*catchall}",
        defaults: new { controller = "Home", action = "RedirectToDefaultCulture", language = "en" });
        });

I inserted some log statements inside RedirectToDefaultCulture action method. It seems the home controller is not being hit when there is no / at the end of the URL

I enabled the Developer Exception and it is not showing me an error

I also tried to give default values to LocalizedDefault route with no luck.

I was successful in loading the home page by going domain.com/myApp/Index (no forward slash at the end)

Shouldn't the default endpoint catch the route?

Mikey
  • 49
  • 7
  • 1
    500 means an unhandled exception was thrown. You'd get a 404 if the page couldn't be found. You need to look at the application logs or enable the developer exception page middleware – Camilo Terevinto Nov 28 '20 at 21:39
  • @CamiloTerevinto I have app.UseDeveloperExceptionPage() in the cofigure method and it is not showing me an error – Mikey Nov 28 '20 at 21:46
  • https://stackoverflow.com/questions/36151471/trailing-slash-issue-in-iis-8-5 Maybe this can help you out, I also had that problem b4 with mine MVC app. – Maurice Pheyton Nov 28 '20 at 22:48
  • @mauricepheyton I tried that with no luck. I even tried to define seperate routing with no luck too – Mikey Nov 29 '20 at 22:02

1 Answers1

0

The answer was steering at me.

I injected RequestLocalizationOptions in the configure method in startup.cs but in the class RouteDataRequestCultureProvider : RequestCultureProvider i was expecting the url to have a / at the end final code:

string twoLetterCultureName = string.Empty;
if (httpContext.Request.Path.Value.EndsWith('/'))
{
    twoLetterCultureName = httpContext.Request.Path.Value.Split('/')[IndexOfCulture]?.ToString();
}
else
{
    if (httpContext.Request.Path.Value.Contains("en")) twoLetterCultureName = "en";
    else twoLetterCultureName = "fr";
}

I feel so bad!

Thanks for everyone for helping me solve this bug

Mikey
  • 49
  • 7