mauricioaniche / restfulie.net

.net version of restfulie server
http://restfulie.caelum.com.br
Other
50 stars 17 forks source link

304 Not Modified tries to respond with View #10

Closed dotnetchris closed 12 years ago

dotnetchris commented 12 years ago

I'm not sure if this is some kind of compound issue as I couldn't seem to reproduce this directly in the sample Web.csproj on restfulie.

I'm having an issue where I respond to a regular browser request after checking the Request.Headers["If-Modified-Since"] with a new NotModified() restfulie result. Instead of it returning to the browser immediately, it actually tries to respond with the view which then blows up spectacularly because the model is null.

As a temporary work around I had to create this class:

public class ReallyNotModified : ActionResult
{
    public override void ExecuteResult(ControllerContext context)
    {
        var response = context.HttpContext.Response;
        response.StatusCode = 304;
        response.StatusDescription = "Not Modified";

        new EmptyResult().ExecuteResult(context);
    }
}

And respond with this instead of the restfulie result.

AlbertoMonteiro commented 12 years ago

I tried to reproduce the trouble but nothing happened, in the actual restifulie web project I tried

private static int _total;
public virtual ActionResult Get(int id)
{
    var item = database.List().SingleOrDefault(i => i.Id == id);

    if (item == null) return new NotFound();
    if (id == 3)
    {
        if (_total++ % 2 != 0)
            return new NotModified();
    }
    return new OK(item);
}

I requested it via jQuery

$.get("http://localhost:1198/Items/Get/3")

But nothing happened, the server has not tried to respond with View

dotnetchris commented 12 years ago

I could never reproduce this outside of my solution, so I'm just going to close this for now unless I come up with anything new.