asp.net mvc的2 - 失去的授权时,RedirectToAction使用JSON数据 [英] asp.net mvc 2 -- losing authorization when RedirectToAction with JSON data

查看:279
本文介绍了asp.net mvc的2 - 失去的授权时,RedirectToAction使用JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重构一些MVC code,它最初使用的 POST'ed表单数据。表单的字段使用jQuery的序列化()方法,序列化和发送到MVC控制器保存操作,检查的事情了和重定向作为合适的(如果表单值的误差,重定向到编辑操作,如果细则保存并重定向到显示屏操作)。一切行动都是通过AJAX调用和返回管窥。一切正常隆重。注:该网站使用AD的授权,因此被提示输​​入他们的Windows用户在第一次加载该网站的凭据,但永远不会再提示

I'm refactoring some MVC code that originally used POST'ed form data. The form's fields are serialized using jquery's serialize() method and sent to an MVC controller Save Action that checks things out and redirects as appropriate (if errors in form values, redirect to the Edit Action, if fine then save and redirect to the Display Action). All actions are invoked via AJAX and return Partial Views. Everything works grand. Note: The site uses AD-based authorization, so users are prompted for their windows credentials upon first loading the site, but are never prompted again.

不过,我现在希望通过JSON服务器互动对象,而不是表单字段。当然,我序列化的JSON对象在客户端上,并与进口MVC2期货/ MVC3类 JsonValueProviderFactory ,我能够正确模拟绑定发送JSON对象到的援助C#类在控制器的参数。

However, I'm now looking to interact with the server via JSON objects instead of form fields. Granted, I serialize the JSON object on the client and, with the aid of an imported MVC2 Futures/MVC3 class JsonValueProviderFactory, am able to correctly model bind the sent JSON object to a C# class in the Controller's parameters.

我保持同样的逻辑,但事情开始炸毁当我试图返回RedirectToAction的ActionResult当控制器接受JSON对象。我失去了身份验证,被再次提示输入其凭据的用户,我发现自己在最初请求的操作(保存)一个无限循环。每次提示用户的凭据,并通过简单的保存操作运行了。用户的最终结果是一个永无止境的警报提示输入登录凭据。无论是在RedirectToAction调用指定的动作是不断袭来。

I maintain the same logic, but things start to blow up when I try to return a RedirectToAction ActionResult when the Controller accepts JSON objects. I lose authentication, the user is prompted for their credentials again, and I find myself in a infinite loop on the originally requested Action (save). Every time the user is prompted for credentials and simply runs through the Save Action again. The end result for the user is an unending alerts prompting for login credentials. Neither of the actions specified in the RedirectToAction calls are ever hit.

可以在原来的要求使用JSON的contentType与RedirectToAction的行为干预的事实?这是我唯一能想到的,因为它正常工作时我不使用JSON发布的而且,当我返回PartialViews,而不是使用RedirectToAction工作正常。控制器动作和授权证书不断流失的无限重复似乎表明RedirectToAction是不是要走的路在这种情况下。

Can the fact that the original request uses a JSON contentType be interfering with the behavior of RedirectToAction? That's the only thing I can think of as it works fine when I don't use JSON to post and it works fine when I return PartialViews instead of using RedirectToAction. The infinite repeat of the Controller Action and continual loss of authorization credentials seems to suggest that RedirectToAction is not the way to go in this situation.

我可以张贴code的请求。我也成功地处理这样的东西复制的ModelState交给TempData的和其他RedirectToAction招数。再次,它当使用非JSON溶液工作。任何有识之士大大AP preciated !!

I can post code on request. I am also successfully handling stuff like copying the ModelState over to TempData and other RedirectToAction tricks. Again, it DOES work when using a non-JSON solution. Any insight is greatly appreciated!!

修改随访信息:

事实证明,我甚至得到一个未经授权的错误,当我完全禁用NTLM身份验证/授权的网站。 IIS服务器不找任何授权的,网站不找任何授权,但试图重定向使用JSON的contentType请求时仍然出现错误和抱怨的是未授权。这很奇怪。

Turns out, I get an "Unauthorized" error even when I completely disable NTLM authentication/authorization for the site. IIS server doesn't look for any authorization, web site doesn't look for any authorization, yet the error when trying to Redirect with JSON contentType request still occurs and complains of being "Unauthorized". This is WEIRD.

推荐答案

要更新大家,我还没有找到一个解决方案,我也不知道,知道什么情况。不过,我愿意打赌它必须与RedirectToAction问题HTTP GET请求,我将重定向到只有行动接受职位的事实。即使我解除限制,它仍然发送JSON数据,它仍然需要由POST完成。

To update everyone, I haven't found a solution nor do I know for-sure what the situation is. However, I'm willing to bet it has to do with the fact that RedirectToAction issues http GET requests and the action I'm redirecting to only accepts POSTs. Even if I remove the restriction, it's still sending JSON data and it still needs to be done by POST.

总之, RedirectToAction使用JSON数据似乎是从根本上撤销的。您需要张贴JSON数据,但RedirectToAction发出GET请求。这就是我要去的理论,至少。 =)

In short, RedirectToAction with JSON data appears to be fundamentally undoable. You need to POST JSON data but RedirectToAction emits GET requests. That's my going theory, at least. =)

这篇关于asp.net mvc的2 - 失去的授权时,RedirectToAction使用JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆