[Authorize] redirection SPA (server and client) #309

Closed
opened 2025-08-09 17:15:48 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @HelloMyDevWorld on 11/23/2017

Hello,

Could anyone tell how should i redirect SPA application from server or is it possible.

After unauthorized access my server redirect me to "/" page, but SPA aplication stay on the same site "/Edit", when i hit AJAX obvoiusly i can check if it's authorized or no and redirect SPA. But is it possible to say form server SPA that should change url ???

            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.HttpOnly = true;
                options.Cookie.Expiration = TimeSpan.FromDays(150);
                options.LoginPath = "/api/login";
                options.LogoutPath = "/api/logout";
                options.SlidingExpiration = true;
                // Requires `using Microsoft.AspNetCore.Authentication.Cookies;`
                options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
                    routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
            });

        [HttpGet]
        [Route("login")]
        public IActionResult Login(string id)
        {
            Response.StatusCode = 302;
            return Redirect("/");
        }

I suppose only server side is redirected "whatever it means" and the client side stay on the same page.

*Originally created by @HelloMyDevWorld on 11/23/2017* Hello, Could anyone tell how should i redirect SPA application from server or is it possible. After unauthorized access my server redirect me to "/" page, but SPA aplication stay on the same site "/Edit", when i hit AJAX obvoiusly i can check if it's authorized or no and redirect SPA. But is it possible to say form server SPA that should change url ??? ``` services.ConfigureApplicationCookie(options => { options.Cookie.HttpOnly = true; options.Cookie.Expiration = TimeSpan.FromDays(150); options.LoginPath = "/api/login"; options.LogoutPath = "/api/logout"; options.SlidingExpiration = true; // Requires `using Microsoft.AspNetCore.Authentication.Cookies;` options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter; }); ``` ``` app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" }); }); ``` ``` [HttpGet] [Route("login")] public IActionResult Login(string id) { Response.StatusCode = 302; return Redirect("/"); } ``` I suppose only server side is redirected "whatever it means" and the client side stay on the same page.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#309
No description provided.