Reputation: 4506
With ASP.NET, can I set Response.StatusCode
to (int)HttpStatusCode.Gone
and still serve the rest of the content of the page to the user? It seems the moment I set the StatusCode
to a 410
the content of the page is removed and replaced with a generic message.
I know that ASP.NET allows me to change the style of the default error pages, but I don't think that's what I want in this case; I don't want the content of this page to be the default for all 410
errors on the website.
Upvotes: 4
Views: 2331
Reputation: 1356
I've achieved this in the past by simply overriding the OnInit method of the Page and forcing it to return the desired HTTP Status Code. I've had to use this technique when creating custom error pages to insure that the proper HTTP Status Code is returned.
using System;
using System.Web.UI;
namespace Website
{
public partial class _410 : Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.Buffer = true;
Response.StatusCode = 410;
Response.Status = "410 Gone";
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Upvotes: 3