小编Cer*_*Cer的帖子

SmtpClient.Send 不适用于 linux 环境

以下代码在.net core 2环境中编写,the windows environmentthe linux environment.

string host = "10.99.99.10";
int port = 25;
string userName = "user@user.com";
string password = "password";
string from = userName;

var client = new SmtpClient
{
    Host = host,
    Port = port,
    EnableSsl = false,
    DeliveryMethod = SmtpDeliveryMethod.Network,
    UseDefaultCredentials = false,
    Credentials = new NetworkCredential(userName, password)
};

MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(from);
mailMessage.To.Add(userName);
mailMessage.Body = "This is test mail.";
mailMessage.Subject = "Testing";                
client.Send(mailMessage); …
Run Code Online (Sandbox Code Playgroud)

c# linux .net-core asp.net-core asp.net-core-2.0

5
推荐指数
1
解决办法
1974
查看次数

异步操作 - MVC

我知道异步方法的逻辑,但我不明白以下方法如何给我带来好处。以下异步方法与同步方法不同吗?

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
    if (User.Identity.IsAuthenticated)
    {
        return RedirectToAction("Index", "Manage");
    }

    if (ModelState.IsValid)
    {
        var info = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (info == null)
        {
            return View("ExternalLoginFailure");
        }
        var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
        var result = await UserManager.CreateAsync(user);
        if (result.Succeeded)
        {
            result = await UserManager.AddLoginAsync(user.Id, info.Login);
            if (result.Succeeded)
            {
                await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                return RedirectToLocal(returnUrl);
            }
        }
        AddErrors(result);
    }

    ViewBag.ReturnUrl = returnUrl;
    return …
Run Code Online (Sandbox Code Playgroud)

c# async-await asp.net-mvc-5

2
推荐指数
1
解决办法
3822
查看次数