【发布时间】:2019-05-17 23:08:45
【问题描述】:
我正在使用 Asp.net Core2.1 Razor 页面技术。
我想询问有关在剃须刀页面之间传递和验证参数的问题。 请不要说我问的是概念而不是编码:
现在假设我有博客,并且每个博客都归一个可以管理它的用户所有。
用户使用此 url 进入管理页面:
https://localhost:44368/blogs/1/settings
如你所见,博客的 id 在 url 中:
public async Task<IActionResult> OnGetAsync(int? id)
{
// here i check that the blog is exist by the id
// and i check if the current user own the blog
}
然后在设置页面我有几个页面的链接,例如(文章) 并且用户可以管理这些文章。
https://localhost:44368/blogs/1/settings/articles
如你所见,我仍然在 url 中有博客 ID:
public async Task<IActionResult> OnGetAsync(int? id)
{
// now this function in the articles page
// again i check if the blog is exist
// and again i check if the current user can manage the blog or not
}
这是正确和好的做法吗?在每个页面中检查和验证
或者我应该只在进入设置页面时检查?
或者我应该考虑一种方法,当用户进入设置页面时只检查一次,然后用户不能根据第一次检查进入其他页面!
【问题讨论】:
标签: c# asp.net asp.net-core-2.1 razor-pages