0

I am trying to change the default Razor scaffolded pages to allow users with blank passwords to be redirected to a page to change them. This is for an internal app where new people will be using the same accounts (They are week long contractors for a help desk system). I am following this post Creating Users with No Password using ASP.NET Identity with the response from Gzim Helshani. When I enter in the code: var user = _context.AspNetUsers.First(p => p.UserName); I receive an error message. The error message reads:

Severity Code Description Project File Line Suppression State Error CS1662 Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type \Areas\Identity\Pages\Account\Login.cshtml.cs 77 Active

and that I cannot implicitly convert type string to bool. I am very new to ASP.Net and I am wondering how I can get around this error. Any help can be appreciated.

Jakxna360
  • 857
  • 2
  • 9
  • 31
  • 2
    You need an expression inside `First()` that produces a `bool`, and what you have is a `string`. Did you mean to use `First(p => p.UserName == "Bob");` for example? – A Friend Jun 26 '19 at 08:23
  • 1
    As with what @AFriend is saying, you need to change the projection in the lambda expression. Currently, it says `First(p => p.UserName)` which means "Get me the first item with a UserName property). Are you searching for the user with a specific username? – Jamie Taylor Jun 26 '19 at 08:31
  • Doh... that makes a lot of sense. In my case I matched it to the Input.Email so that it is now: ```var user = _context.AspNetUsers.First(p => p.Email == Input.Email);``` Thank you so much guys for your help! – Jakxna360 Jun 26 '19 at 08:37

1 Answers1

1

Thank you A Friend and Jamie Taylor for the help. I changed my Expression to the following:

var user = _context.AspNetUsers.First(p => p.Email == Input.Email);
Jakxna360
  • 857
  • 2
  • 9
  • 31