开发者

IE8 not POSTing data after 307 redirect from ASP.NET

I'm (re)writing a RESTful resource scheduler app using ASP.NET 3.5/SQL Server as the backend, and jQuery/Backbone.js as the front. In ASP.NET, I'm using WCF services, with RouteTable routes to route requests to the appropriate WCF class. In my Global.asax file, I have:

System.Web.Routing.RouteTable.Routes.Add( 
      new System.ServiceModel.Activation.ServiceRoute( 
           "events", factory, typeof( Scheduler.Events ) ) );

In App_Code, my IEvents.cs has this:

[WebInvoke( Method = "POST", ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "",
            BodyStyle = WebMessageBodyStyle.WrappedRequest )]
SchedulerEvent SaveNewEvent ( SchedulerEvent schedulerEvent );

And Events.cs has the SaveNewEvent function does all the magic.

Because of the routing, the server returns a 307 response for POSTs to /events. Chrome, Safari, and Firefox all do what's expected, which is rePOST the request to the new location and then process the response. IE8 (which is all I've tested, but it's all we run here) gets the 307, but issues a GET to the new URL which doesn't do me any good because no data is POSTed and saved. I know this because I used Fiddler to track the requests from IE, and when I debug the server-side code, SaveNewEvent is never called.

Interestingly, PUT and DELETE requests from IE work fine.

I find it hard to believe that PUT and DELETE would work, but POSTs wouldn't. Am I missing something? I can't find any info on IE8 that suggests this is broken. Is there a way to have ASP.NET ro开发者_如何学运维ute by issuing a 302 redirect? And would that work?

Any experiences, insights, suggestions, or ideas are appreciated.


While the RFC states that 302 should always ask the user, most browsers implement it as 303 See Other and accordingly GET on the LOCATION. While this isn't strictly HTTP 1.1, you can't do anything about it and need to work with the behaviour of the browsers. I encountered the same problem and needed to work around it as well.


After giving the problem some space, I came back to it and found out that the 307 Temporary Redirect wasn't being caused by the ServiceRoutes, but by how my services were being accessed in the Javascript. I was missing the trailing slash in my service URLs. D'oh:

EVENTS_URL: "/events"

should have been

EVENTS_URL: "/events/"

No more redirect, POSTs work great.

Unrelated to my problem, but related to WCF services, while getting to the bottom of this, I came across these two pages which helped me clean up my WCF code. FYI:

http://geekswithblogs.net/michelotti/archive/2010/08/21/restful-wcf-services-with-no-svc-file-and-no-config.aspx

404 when running .net 4 WCF service on IIS (no svc file)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜