Comments (18)
I tried to reproduce with the Sample Project.
I added Microsoft.Owin.Host.SystemWeb and Microsoft.AspNet.Identity.Owin. This is my StartUp Configuration:
public class StartUp
{
public void Configuration(IAppBuilder appBuilder)
{
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(url.Action(MVC.Home.Index()))
});
}
}
I decorated HomeWithRoutePrefixAttributeController with [Authorize]. When accessing HomeWithRouteArea/Welcome I'm redirected to Welcome?ReturnUrl=%2Fen%2FHomeWithRouteArea%2FWelcome. Am I something missing?
from routelocalization.
Are you using culture prefix in the routes? The onde way I was able to make
this work was setting the login path to '/pt/entrar' instead of getting
from the action. But in this case i am not able to localize it.
Em 11/07/2014 07:11, "Dresel" [email protected] escreveu:
I tried to reproduce with the Sample Project.
I added Microsoft.Owin.Host.SystemWeb and
Microsoft.AspNet.Identity.Owin. This is my StartUp Configuration:public class StartUp
{
public void Configuration(IAppBuilder appBuilder)
{
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(url.Action(MVC.Home.Index())) }); }
}
I decorated HomeWithRoutePrefixAttributeController with [Authorize].
When accessing HomeWithRouteArea/Welcome I'm redirected to
Welcome?ReturnUrl=%2Fen%2FHomeWithRouteArea%2FWelcome. Am I something
missing?â
Reply to this email directly or view it on GitHub
#16 (comment)
.
from routelocalization.
If I understand correctly you want to be redirected to the localized login method?
from routelocalization.
Yes, because the login will bĂŞ made by people that will only understand one
of the languages.
Em 11/07/2014 09:39, "Dresel" [email protected] escreveu:
If I understand correctly you want to be redirected to the localized login
method?
â
Reply to this email directly or view it on GitHub
#16 (comment)
.
from routelocalization.
Well if you set LoginPath, this is a fixed path for all requests. You could use OnApplyRedirect to dynamically redirect to a localized route:
appBuilder.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(url.Action(MVC.User.Login())),
Provider =
new CookieAuthenticationProvider()
{
OnApplyRedirect =
context => context.Response.Redirect(
url.Action(MVC.User.Login().AddRouteValues(new { culture = Thread.CurrentThread.CurrentCulture.Name })))
}
});
Here you would be redirected to the current thread culture which could e.g. be set by CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate.
from routelocalization.
That was something I tried ... I do have the following on Application_Start:
CultureSensitiveHttpModule.GetCultureFromHttpContextDelegate = context => { return context.GetCulture(); };
And to test I used the extension as follows:
public static CultureInfo GetCulture(this HttpContext context) {
return new CultureInfo("pt");
But when I try to access an action with Authorize I keep getting the 401 error and not being redirected ...
from routelocalization.
What URL is generated - you will get the 401 error if it does not exist.
from routelocalization.
The user signin action is as follows:
[Route("entrar"), HttpGet]
public virtual ActionResult SignIn() { }
I am able to access it using, as expected due to the translation I am using:
/pt/entrar
/en/signin
I typed both in the URL and they work ... And I get the right culture in each one.
The action with Authorize attribute is:
[RouteArea("cms", AreaPrefix = "cms")]
public partial class HomeController : Controller {
[Route("inicio", Name = "cms.home.index"), HttpGet] { }
}
I am able to access it, after being autenticathed, typing in the url bar:
pt/cms/inicio
This is the only route I have for CMS home page. I am not translation the CMS routes ...
In fact the prefix didn't needed to be added to the CMS routes.
Basically this is a situation where the website is in many languages but the CMS only in one.
But the login page should be in different languages because there are reserved areas which are also in different languages.
from routelocalization.
What URL does
url.Action(MVC.User.Login().AddRouteValues(new { culture = Thread.CurrentThread.CurrentCulture.Name }))
in OnApplyRedirect produce?
from routelocalization.
When I try:
var test = url.Action(MVC.User.SignIn().AddRouteValues(new { culture = Thread.CurrentThread.CurrentCulture.Name }));
On owin setup test is null ... Not sure if this is what you were asking.
Are translated routes already available when Owin starts?
from routelocalization.
I don't know - my StartUp is called after RegisterRoutes.
What I asked is do you use OnApplyRedirect as shown before?
Provider =
new CookieAuthenticationProvider()
{
OnApplyRedirect =
context => context.Response.Redirect(
url.Action(MVC.User.Login().AddRouteValues(new { culture = Thread.CurrentThread.CurrentCulture.Name })))
}
If so, what URL is generated there? You have to use OnApplyRedirect because that is called for each Request and you can there switch to different Logins. If you only set the LoginPath, you can only redirect to this one specific URL.
I don't know why your URL is NULL there though.
from routelocalization.
This is a really strange issue as I confirmed that my Routes are being added before calling Owin.
Then on Owin setup I tried the following:
UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);
// Testing routes > All returned null
var home = url.Action("home", "index");
var homeT4MVC = url.Action(MVC.Home.Index());
var login = url.Action("user", "login");
var loginT4MVC = url.Action(MVC.User.Login());
In url I confirmed there are 116 routes ... So at least the Home/Index should not return null.
I will try to replicate this in the sample project but this is quite strange.
from routelocalization.
You can also upload your project to a github repository, and i will take a look then if thats easier for you.
from routelocalization.
Thanks. I will do that tomorrow. I will try to replicate the situation and upload it to Github.
from routelocalization.
Any update on this issue?
from routelocalization.
If you run the project https://github.com/mdmoura/RouteLocalization.Test you will see two buttons.
One accesses tries to access an action with Authorize attribute. You will see a 403 error.
Something is wrong when using RouteLocalization and Owin ... Or maybe my configuration?
Please, see the RouteConfig and Startup.Auth files in App_Start ... Note the code line:
OnApplyRedirect = context => context.Response.Redirect(url.Action(MVC.Account.Login().AddRouteValues(new { culture = Thread.CurrentThread.CurrentCulture.Name })))
OnAppluRedirect works fine when not using RouteLocalization.
from routelocalization.
It seems when LoginPath isn't set at all, OnApplyRedirect is not called. Try to comment
// LoginPath = new PathString("/Account/Login")
in, then it should work.
from routelocalization.
Yes, that is right ... Solved.
I get back to this if I find any other problem.
from routelocalization.
Related Issues (20)
- Problem with Link Generation for Route HOT 3
- Difficulty redirecting to correct culture/prefix from non-default culture HOT 3
- Assembly sign is missing
- Some notes from the MVC team HOT 5
- How to route sitemap.xml HOT 2
- No License File? HOT 1
- How to add translations to other controllers in core branch HOT 4
- ActionModels with AttributeRoutes was expected HOT 4
- ArgumentException: An element with the key 'culture' already exists in the RouteValueDictionary. HOT 6
- Default culture in routes? HOT 2
- Make route ignore culture parameter HOT 2
- Force route to have culture value in URL HOT 1
- Get RouteValues from url string HOT 2
- Controller part is not translated HOT 2
- Adding localtization for actions containing parameters HOT 4
- AddCultureAsRoutePrefix only for one language HOT 2
- GetRouteData return empty WebAPI route instead valid MVC route HOT 2
- The state of ASP.NET Core branch HOT 6
- Is translations possible using only route attributes? HOT 6
- It seems ActionFilter is too late to apply current culture HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ď¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routelocalization.