Reputation: 17
I can not really find out where along in the code I need to set my "await" so it run my code through to enable users to log in to the site.
Where the problem lies is where should I set my "await" when the user has success by log in to the site.
Error:
'UserLogin' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'UserLogin' could be found (are you missing a using directive or an assembly reference?)
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> login(UserLogin UserValue)
{
//Makes database access
DataLinqDB db = new DataLinqDB();
if (ModelState.IsValid)
{
//Is this email and also downloads "salt" from the mail.
var email = db.brugeres.FirstOrDefault(i => i.brugernavn == UserValue.Brugernavn);
if (email != null)
{
//Makes password on the SHA256
var pass = HelperClass.Helper.Hash.getHashSha256(UserValue.Brugernavn);
//Checker up for a username and password match up with what you have written in.
//Checks also while on the salt as the few from the past to the fit with "email"
var User = db.brugeres.FirstOrDefault(u => u.brugernavn == UserValue.Brugernavn && u.adgangskode == pass && u.salt == email.salt);
if (User != null)
{
.... code her ....
//Sending me over to the front. (the closed portion.)
await UserValue; //Error here!!!
return RedirectToAction("index");
}
else
{
//Error - Invalid username and password do not match.
ModelState.AddModelError("", "Unfortunately, it is wrong ..");
}
}
else
{
//Error - Invalid username do not match.
ModelState.AddModelError("", "We could not find you!");
}
}
return View();
}
There where the fault lies here.
//Sending me over to the front. (the closed portion.)
await UserValue;//Error here!
return RedirectToAction("index");
Upvotes: 0
Views: 931
Reputation: 218732
UserValue
is your method parameter and why you want to await that ?
You might use await
when you query your burgers table.You can use the FirstOrDefaultAsync
method which is awaitable
.
var email = await db.brugeres
.FirstOrDefaultAsync(i => i.brugernavn == UserValue.Brugernavn);
if (email != null)
{
//Continue with your other code (Password checking)
//Make sure you remove the await UserValue line :)
}
FirstOrDefaultAsync
is an extension method available in System.Data.Entity
namespace, which is in EntityFramework.dll
. The version i checked is the latest stable one as of today, Which is EntityFramework 6.1.3 If you are not able to access this extenstion method, you might be using an old version of EF. Please update it to the latest stable from nuget.
Upvotes: 3