Skip to content

Commit

Permalink
added a simple redirect result that will use 303 and show that even w…
Browse files Browse the repository at this point in the history
…hen using 303 - chrome still fails.

now you can see both options are effed
  • Loading branch information
avipinto committed Apr 2, 2012
1 parent 393cea3 commit d8066a2
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ChromePRG/ChromePRG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\SeeOtherRedirectResult.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -77,14 +78,13 @@
<Content Include="Content\Site.css" />
<Content Include="Views\_ViewStart.cshtml" />
<Content Include="Views\Home\NewSomething.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Views\Home\Grid.cshtml" />
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Web.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Models\" />
<Folder Include="Scripts\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
22 changes: 17 additions & 5 deletions ChromePRG/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ namespace ChromePRG.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
public ActionResult Grid()
{
return View();
}

public ActionResult NewSomething()
public ActionResult RedirectWith302()
{
return View();
return View("NewSomething");
}

[HttpPost]
public ActionResult RedirectWith302(string someData)
{
return RedirectToAction("Grid");
}


public ActionResult RedirectWith303()
{
return View("NewSomething");
}

[HttpPost]
public ActionResult NewSomething(string someData)
public ActionResult RedirectWith303(string someData)
{
return RedirectToAction("index");
return new SeeOtherRedirectResult(this.HttpContext.Request.RequestContext, "Grid", "Home");
}
}
}
2 changes: 1 addition & 1 deletion ChromePRG/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void RegisterRoutes(RouteCollection routes)
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
new { controller = "Home", action = "Grid", id = UrlParameter.Optional } // Parameter defaults
);

}
Expand Down
61 changes: 61 additions & 0 deletions ChromePRG/Models/SeeOtherRedirectResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.Mvc;
using System.Web.Routing;

namespace ChromePRG
{
/// <summary>
/// use this to redirect with 303 result
/// return this when redirecting after a post request
/// </summary>
public class SeeOtherRedirectResult : ActionResult
{
public string Url { get; set; }

public SeeOtherRedirectResult(string url)
{
this.Url = url;
}

public SeeOtherRedirectResult(RequestContext context, string actionName, string controllerName)
{
UrlHelper urlHelper = new UrlHelper(context);
string url = urlHelper.Action(actionName, controllerName);

this.Url = url;
}

public SeeOtherRedirectResult(RequestContext context, string actionName, string controllerName, object values)
{
UrlHelper urlHelper = new UrlHelper(context);
string url = urlHelper.Action(actionName, controllerName, values);

this.Url = url;
}

public SeeOtherRedirectResult(RequestContext context, string actionName, string controllerName, RouteValueDictionary values)
{
UrlHelper urlHelper = new UrlHelper(context);
string url = urlHelper.Action(actionName, controllerName, values);

this.Url = url;
}

public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.HttpContext.Response.StatusCode = 303;
context.HttpContext.Response.RedirectLocation = Url;
context.HttpContext.Response.End();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

<h2>Showing a bug in Chrome History</h2>
<p>Let's assume this is a grid, showing a lot of data. <br />
and there is this link to add more data @Html.ActionLink("Click me to go to the form","NewSomething")
and there is this link to add more data @Html.ActionLink("Click me to go to the form", "RedirectWith302")
<br /><br />
NOTE: even when using a form that redirects with 303, this problem happens <br />
here is a link to a form that after post will redirect with 303: @Html.ActionLink("Click me to go to the form that redirects with 303", "RedirectWith303")
</p>

Open this site in Chrome and to the following:
Expand Down
2 changes: 1 addition & 1 deletion ChromePRG/Views/Home/NewSomething.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ViewBag.Title = "About Us";
}

<h2>I do regular post redirect get and i post back to the Index(Grid)</h2>
<h2>I do regular post redirect get and i post back to the Grid</h2>
<p>Just click the submit button, and then return here and submit again</p>
@using (Html.BeginForm()){
@Html.Label("someData", "enter some data:") @:&nbsp; @Html.TextBox("someData")
Expand Down
4 changes: 2 additions & 2 deletions ChromePRG/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<header>
<nav>
<ul id="menu">
<li>@Html.ActionLink("Grid", "Index", "Home")</li>
<li>@Html.ActionLink("Form", "NewSomething", "Home")</li>
<li>@Html.ActionLink("Grid", "Grid", "Home")</li>
@* <li>@Html.ActionLink("Form", "RedirectWith302", "Home")</li>*@
</ul>
</nav>
</header>
Expand Down

0 comments on commit d8066a2

Please sign in to comment.