【发布时间】:2016-01-01 22:28:17
【问题描述】:
我真的不知道我需要在代码中的哪个位置设置我的“等待”,因此它运行我的代码以使用户能够登录到该站点。
问题出在哪里,当用户登录网站成功时,我应该在哪里设置“等待”。
错误:
“UserLogin”不包含“GetAwaiter”的定义,也没有 扩展方法“GetAwaiter”接受类型的第一个参数 可以找到“UserLogin”(您是否缺少 using 指令或 汇编参考?)
[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();
}
错在哪里。
//Sending me over to the front. (the closed portion.)
await UserValue;//Error here!
return RedirectToAction("index");
【问题讨论】:
-
在那个逻辑分支中,似乎没有任何东西可以等待。
UserValue只是一个UserLogin对象,无需等待。 -
实际上似乎根本没有什么可以等待正如你所写的,至少据我们所知。
-
@GlorinOakenfoot 你对你写的东西有什么看法? / 在这里给我解释一下?
-
你只能
await可以等待的东西(错误建议有GetAwaiter方法),通常是Task。 -
await等待异步函数的结果。UserValue绝对不是一个异步函数,因为它是您提供的数据。通常异步函数在名称的末尾标有“Async”。您在这里根本没有什么可以等待的,因为没有什么明显是 Async 函数。
标签: c# asp.net-mvc asynchronous