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

Login link not generated after following all the steps #8201

Closed
hmihail opened this issue Aug 21, 2018 — with docs.microsoft.com · 12 comments
Closed

Login link not generated after following all the steps #8201

hmihail opened this issue Aug 21, 2018 — with docs.microsoft.com · 12 comments
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Milestone

Comments

Copy link

hmihail commented Aug 21, 2018

I followed all the steps here, and after switching primary key to <int>, the 'Register' and 'Login' links are not generated anymore. In my html page I have just this:
<a class="nav-link" href="">Login</a>

but the code looks like this:
<li class="nav-item"><a asp-page="/Account/Login" class="nav-link">Login</a></li>

For the page to work, I had to change the @Inject statements like this:

@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager 

Anyone has an ideea why?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@Rick-Anderson
Copy link
Contributor

@hmihail routing needs a valid route to generate a link.

For the page to work, I had to change the @Inject statements like this:

So is everything working? What's the correct URI for Login?

@Rick-Anderson Rick-Anderson added Pri3 Priority 3 Source - Docs.ms Docs Customer feedback via GitHub Issue question labels Aug 22, 2018
@Rick-Anderson Rick-Anderson added this to the Backlog milestone Aug 22, 2018
Copy link
Author

hmihail commented Aug 23, 2018

The URI should by /Account/Login, but even if I enter in the browser that addres, I get 404:
No webpage was found for the web address: https://localhost:44305/Account/Login

@Rick-Anderson
Copy link
Contributor

Try https://localhost:44305/Identity/Account/Login

@Rick-Anderson
Copy link
Contributor

The links are not generated because you don't have a valid route. I'm not sure what you did wrong. You can probably get a quicker response on StackOverflow.

The login page doesn't use route data - so changing the PK doesn't affect routing.

@hmihail
Copy link
Author

hmihail commented Aug 24, 2018

I did nothing else, it was an empty project. I just followed the instructions here.

With the link https://localhost:44305/Identity/Account/Login it works.
I tried StackOverflow, but nobody answered :(

I can provide the source code if necessary.

@Rick-Anderson
Copy link
Contributor

the link https://localhost:44305/Identity/Account/Login works.

That's because you're using the new 2.1 templates which use /Identity for the area. Your problem has nothing to do with changing the PK. You must have 2.0 code mixed with 2.1 code.

See

Copy link
Author

hmihail commented Aug 27, 2018

You are right, thanks for pointing that out. I have copied the LoginPartial code from somewhere, and missed the asp-area="Identity".

Thank you!

@Rick-Anderson Rick-Anderson added P4 and removed Pri3 Priority 3 labels Aug 27, 2018
Copy link
Contributor

chpong commented Sep 19, 2018

I created an ASP.NET Core 2.1 MVC app with authentication enabled using individual user accounts (store user accounts in-app), and verified that the Identity's register and login links are generated correctly:

  • https://localhost:XXXXX/Identity/Account/Register
  • https://localhost:XXXXX/Identity/Account/Login

I followed the steps in this doc to change the identity user and identity role primary key to Guid. But it didn't work (bug for this doc?) because I also need to update the Views/Shared/_LoginPartial.cshtml with the following:

  • @inject SignInManager<ApplicationUser> SignInManager
  • @inject UserManager<ApplicationUser> UserManager

After that, I notice the Identity's register and login links are generated correctly. They became "unrouted":

  • https://localhost:XXXXX/?area=Identity&page=%2FAccount%2FRegister
  • https://localhost:XXXXX/?area=Identity&page=%2FAccount%2FLogin

Not only the link are not generated correctly, the previously working URLs stopped showing the register and login page content too:

  • https://localhost:XXXXX/Identity/Account/Register
  • https://localhost:XXXXX/Identity/Account/Login

Is this a known issue? Any idea how I can fix this?

Thank you.

@chpong
Copy link
Contributor

chpong commented Sep 19, 2018

Thanks @Rick-Anderson, @scottaddie, @HaoK and @javiercn for finding the fix.

The solution is to add .AddDefaultUI() in the Startup.cs:

services.AddIdentity<ApplicationUser, ApplicationRole>()
    .AddEntityFrameworkStores<ApplicationDbContext>()
    .AddDefaultUI()
    .AddDefaultTokenProviders();

Note that this solution is applicable to ASP.NET Core 2.1 only, not for 2.0.

See #6967 for similar issue.

@scottaddie
Copy link
Member

I'll be documenting this as part of #8605

@rafaelalmeida12
Copy link

A interface do usuário da identidade é implementada usando o Razor Pages. Para que o roteamento do nó de extremidade os mapeie, adicione uma chamada MapRazorPagesno seu UseEndpointsretorno de chamada:
app.UseEndpoints(endpoints => { // ... endpoints.MapRazorPages(); });

@HousingCode
Copy link

app.UseEndpoints(endpoints => { // ... endpoints.MapRazorPages(); });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

6 participants