授权属性不保留发布数据
为了在控制器方法上使用 [Authorize] 属性后保留发布数据,然后将用户重定向到登录页面,然后在成功验证后将用户重定向到他们打算去的地方 - 这是如何完成的? 默认情况下,不会转发原始表单提交。 对之前帖子的回复说:
您需要将表单值和 RedirectUrl 序列化到隐藏字段。 身份验证后,反序列化隐藏字段中的数据并根据 RedirectUrl 的值进行重定向。 您将需要一个自定义的 Authorize 类来处理这个问题。
我的问题是——有什么例子可以进一步指出我正确的方向吗? 是的,我可以向控制器类添加 [Serialize] 标签,但我不知道创建自定义授权类有何帮助? 我在网上看到了大量有关创建自定义授权类的材料,但是反序列化在哪里完成? 如果你能再深入一两层,将会有很大帮助。 我是新手。
(我会对之前的帖子发表评论,但我是该网站的新手,还没有积累足够的积分。我还会添加另一个帖子的链接,但它说新用户也无法显示链接!)
In order to preserve post data after utilizing the [Authorize] attribute on a controller method, which then redirects the user to a login page, which then upon successful authentication redirects the user to where they were intending to go -- how would this be done? The original form submission is not relayed by default. A response to a previous posting said to:
You need to serialize your form values and a RedirectUrl to a hidden field.
After authentication deserialize the data in your hidden field and redirect based on the value of the RedirectUrl.
You will need a custom Authorize class to handle this.
My question is -- any examples to further point me in the right direction? Yes, I can add a [Serialize] tag to the controller class but I can't figure out how creating a custom Authorize class would help? I see plenty of material online on creating a custom Authorize class but where would the de-serialization be done? It would help greatly if you could go one or two levels deeper. I'm a newbie.
(I would comment on the previous posting but I'm new to the site and have not amassed enough points. I would also put a link to the other posting but it says new users can't show links either!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个自定义授权属性,将表单发布的值存储在会话字典中,然后在授权完成后,您可以从会话字典中恢复这些值。
这是一个示例:
如您所见,在授权之前,所有表单值都存储在会话中。
现在,授权完成后,您可以恢复所有值。
You can create a custom authorization attribue that store the form posted values in the Session dictionary, and then after the authorization has completed you can resotre the values from the Session dictionary.
Here is an example:
As you see, before the authorization all the form values are stored in the session.
Now after the authorization has completed you can restore all the values.