我有一个简单的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,即使它是在前一行中编写的也是如此。
使用该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)