Include a URL fragment in CookieAuthenticationOptions.LoginPath

Omar Emara 96 Reputation points
2021-05-22T10:12:29.86+00:00

The login form is implemented as a modal in one of the pages. I would like to show that modal by including a fragment in the LoginPath for client side logic. I did the following:

services.ConfigureApplicationCookie(options => {
      options.LoginPath = "/Wall/Index/#loginModal";
    });

The problem is that the hash gets encoded as follows Wall/Index/%23loginModal and the browser doesn't interpret it as a fragment anymore. I tried constructing the PathString using FromUriComponent, but the problem persisted.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,165 questions
{count} votes

Accepted answer
  1. Omar Emara 96 Reputation points
    2021-05-23T19:13:07.807+00:00

    As far as I can tell, LoginPath is of type PathString and can only represent a path. Characters that can't be represented in the path, such as #, will be always be encoded.

    The workaround as suggested by @AgaveJoe , is to link to a controller action that can then redirect to the appropriate page with the fragment:

       [AllowAnonymous]  
           public IActionResult LoginModal() { return Redirect("/#loginModal"); }  
    

    One can take the return path as a parameter here and append it as well, but it is not used in my case.

    0 comments No comments

0 additional answers

Sort by: Most helpful