小编Ser*_*ore的帖子

在ASP.NET Core 2.1中使用Cookie

我有一个简单的ASP.NET Core 2.1应用程序,该应用程序应该设置然后读取Cookie。

每当我尝试读取Cookie时,它都会返回null。在浏览器的检查工具中进一步查找,我找不到它。

我想出了一个小小的实现,以查看是否可以弄清发生了什么,但是它不起作用。

 public async Task<IActionResult> Contact(Contato contato)
 {
    await email.SendAsync(contato);

    var option = new CookieOptions();
    option.Expires = DateTime.Now.AddMinutes(10);
    Response.Cookies.Append("EmailEnviado", "true", option);
    var boh = Request.Cookies["EmailEnviado"];

    return RedirectToAction("Contact");
 }
Run Code Online (Sandbox Code Playgroud)

boh通过调试器检查的变量为null,即使它是在前一行中编写的也是如此。

html c# asp.net-mvc asp.net-core

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

using array with array - type必须可以隐式转换为'System.IDisposable'

使用该using语句的以下代码旨在避免某种内存泄漏,这会导致代码在长文件上变慢:

var db = new EntityContext();
var cubos = db.CubosTrabalhados;
var cubo = new CuboTrabalhado();
string[] lines = File.ReadAllLines(Files.cuboHistorico, Encoding.Default);
bool header = true;
int i = 2;

foreach (string line in lines)
{
    if (header) header = false;
    else
    {
        using (var reg = line.Split(';'))
        {
            cubo.Pedido = reg[0];
            cubo.DataPedido = Select.ParseDate(reg[3]);
            cubo.Cliente = reg[4];
            cubo.UF = Select.Uf(reg[5]);
            cubo.Cidade = reg[6];
            cubo.Regiao = reg[7];
            cubo.Codigo = reg[8];
            cubo.Produto = reg[9];
            ...
            cubo.VlCom = Select.ParseFloat(reg[63]);
            cubo.Cnpj = reg[64]; …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net arrays

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

标签 统计

c# ×2

.net ×1

arrays ×1

asp.net ×1

asp.net-core ×1

asp.net-mvc ×1

html ×1