Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

403 error when turning AddCultureAsRoutePrefix from false to true #27

Closed
mdmoura opened this issue Sep 24, 2014 · 10 comments
Closed

403 error when turning AddCultureAsRoutePrefix from false to true #27

mdmoura opened this issue Sep 24, 2014 · 10 comments

Comments

@mdmoura
Copy link

mdmoura commented Sep 24, 2014

Hello,

I have the following actions on an MVC 5.2 web site with Route Localization:

[Route]
public virtual ActionResult Index() { }

[HttpGet, Route("test")]
public virtual ActionResult Test() { }

On this website I do not want to translate any routes. I want only to add the current culture as prefix.

In the future I will add translations so I want to have everything set up. So I have:

    RouteTable.Routes.MapMvcAttributeRoutes(LocalizationDirectRouteProvider);
    RouteTable.Routes.Localization(x => {
      x.AcceptedCultures = new HashSet<String> { "en" };
      x.DefaultCulture = "en";
      x.AttributeRouteProcessing = AttributeRouteProcessing.AddAsDefaultCultureRoute;
      x.AddCultureAsRoutePrefix = false;
      x.AddTranslationToSimiliarUrls = false;
  }).TranslateInitialAttributeRoutes().Translate(x => {  });

  CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = context => { return new System.Globalization.CultureInfo("en"); };

  GlobalFilters.Filters.Add(new CultureSensitiveActionFilterAttribute(true, true));

This works fine but I do not get the culture prefix on my routes.

So I turned Add Culture Prefix to true:

   x.AddCultureAsRoutePrefix = true;

And know I get an

HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.

What am I missing?

Thank You,
Miguel

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

From #18:

.Translate(localization =>
{
    // Foreach defined culture
    localization.Configuration.AcceptedCultures.ToList().ForEach(culture =>
    {
        // For every collected attribute route
        localization.Configuration.LocalizationCollectionRoutes.ForEach(route =>
        {
            // Add translation for this culture with same route as defined in route attribute
            localization.AddTranslation(route.Route.Url(), culture, (LocalizationCollectionRoute)route.Route);
        });
    });
});

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

I misread your post, this should work. I will investigate that.

@mdmoura
Copy link
Author

mdmoura commented Sep 24, 2014

I added the configuration of #18 but it does not work.

I think this would be a nice feature because it allows to set the routes of a web site to:

en/contact ...

And later add translation as:

pt/contacto

without breaking the original routes.

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

Can you show me which routes where created? I used your setup for the test project and it worked.

You should have "/en" and "/en/test" registered.

@mdmoura
Copy link
Author

mdmoura commented Sep 24, 2014

It was added:

en/ (en)
en/Test (en)

Maybe the problem is with home route having en/ ?

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

And you cannot access en/ or en/test?

@mdmoura
Copy link
Author

mdmoura commented Sep 24, 2014

Yes, I can access both ... I am not sure if this is not the problem I had before where I need to add the usual route rule after attribute routing ...

But a route with only Route should be considered the homepage.

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

So you expect to access "/"?

@Dresel
Copy link
Owner

Dresel commented Sep 24, 2014

You could use neutral routes or use

routes.MapRoute("Start", string.Empty, new { controller = "Home", action = "Index" });

Atm AddCultureAsRoutePrefix is added to every route, even to empty ones - it could be discussed if this shouldn't be.

@mdmoura
Copy link
Author

mdmoura commented Sep 24, 2014

I supose that sometimes having the culture prefix on all pages might not be te best option. For example having it in homepage or some not translated pages ...

But maybe others could opinate on this since i am not sure about all scenarios.

@Dresel Dresel closed this as completed May 17, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants