简体   繁体   English

使用cookie将用户信息从一个剃刀页面传送到另一个剃刀页面

[英]Carry user info from one razor page to another using cookies

Currently, I have a form which asks for the primary key and when the user submits it redirects it to another page. 目前,我有一个要求主键的表单,当用户提交时,它会将其重定向到另一个页面。 I want to display the record on another page. 我想在另一页上显示记录。 I have tried creating a cookie but it isnt working. 我试过创建一个cookie,但它不起作用。 When I print the string that should have been stored in cookie it shows nothing. 当我打印应该存储在cookie中的字符串时,它什么也没显示。

You can carry information from one page to other, for example by parametrize your redirect methods in code-behind: 您可以将信息从一个页面传送到另一个页面,例如通过在代码隐藏中参数化重定向方法:

// Page A
public async Task<IActionResult> OnPostAsync() 
{
 //...
 RedirectToPage("PageB", new { PrimaryKey = value});
}

// Page B
public async Task<IActionResult> OnGetAsync(string PrimaryKey)
{
 // use your key
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM