Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Culture is lost when redirect to login #1

Closed
LazZiya opened this issue Sep 26, 2019 · 3 comments
Closed

Culture is lost when redirect to login #1

LazZiya opened this issue Sep 26, 2019 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@LazZiya
Copy link
Owner

LazZiya commented Sep 26, 2019

If unlogged user clicked on a page that requires authorization, the user is redirected to login page but with the culture parameter is lost!

e.g. : unlogged user clicks on below link:
http://localhost:1234/tr/Identity/Account/ChangePassword/
he will be redirected to :
http://localhost:1234/Identity/Account/Login/

@LazZiya LazZiya self-assigned this Sep 26, 2019
@LazZiya LazZiya added the bug Something isn't working label Sep 26, 2019
@LazZiya
Copy link
Owner Author

LazZiya commented Sep 26, 2019

add login redirection rules in startup:

services.ConfigureApplicationCookie(options =>
{
    options.Events = new CookieAuthenticationEvents
    {
        OnRedirectToLogin = ctx =>
        {
            var requestPath = ctx.Request.Path;
            var culture = ctx.Request.RouteValues["culture"];
            ctx.Response.Redirect($"/{culture}/Identity/Account/Login/?ReturnUrl={requestPath}{ctx.Request.QueryString}");
            return Task.CompletedTask;
        }
    };
});

LazZiya added a commit that referenced this issue Sep 26, 2019
LazZiya added a commit that referenced this issue Sep 26, 2019
@LazZiya
Copy link
Owner Author

LazZiya commented Sep 26, 2019

fixed in commit c9b2a7f

@LazZiya LazZiya closed this as completed Sep 26, 2019
@LazZiya
Copy link
Owner Author

LazZiya commented Sep 26, 2019

improved approach provided in commit c1f7e3d

services.ConfigureApplicationCookie(options =>
{
    options.Events = new CookieAuthenticationEvents
    {
        OnRedirectToLogin = ctx =>
        {
            var culture = ctx.Request.RouteValues["culture"];
            var requestPath = ctx.Request.Path;

            if (culture == null)
            {
                culture = "en";
                requestPath = $"/{culture}{requestPath}";
            }

            ctx.Response.Redirect($"/{culture}/Identity/Account/Login/?ReturnUrl={requestPath}{ctx.Request.QueryString}");
            return Task.CompletedTask;
        }
    };

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant