Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 444297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:15:23+00:00 2026-05-12T21:15:23+00:00

I am designing a new dynamic site from a static site. I have the

  • 0

I am designing a new dynamic site from a static site. I have the route all sorted but I have a question on my Action method.

Below is the code but when testing and looking at the headers that Firebug reports, if I take out the Response.End it is a 302 redirect I assume because I set the 301 but then call another action which makes it a 302, but if I put in the Response.End I get a 301.

I am guessing that adding the Response.RedirectLocation is actually doing the 301 redirect so do I therefore change my return value to EmptyResult or null even though that line of code will never get executed just so the app compiles?

public ActionResult MoveOld(string id)
{
    string pagename = String.Empty;

    if(id == "2")
    {
      pagename = WebPage.SingleOrDefault(x => x.ID == 5).URL;
    }

    Response.StatusCode = 301;
    Response.StatusDescription = "301 Moved Permanently";
    Response.RedirectLocation = pagename;
    Response.End();

    return RedirectToAction("Details", new { pageName = pagename });
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:15:24+00:00Added an answer on May 12, 2026 at 9:15 pm

    I echo Levi’s comments. This is not the job of the controller. I have tended to use this custom ActionResult for 301’s. Below is a modified version with more options.

    For ASP.NET MVC v2+, use RedirectResult.

    public class PermanentRedirectResult : ActionResult
    {
      public string Url { get; set; }
    
      public PermanentRedirectResult(string url)
      {
        Url = url;
      }
    
      public PermanentRedirectResult(RequestContext context, string actionName, string controllerName)
      {
        UrlHelper urlHelper = new UrlHelper(context);
        string url = urlHelper.Action(actionName, controllerName);
    
        Url = url;
      }
    
      public PermanentRedirectResult(RequestContext context, string actionName, string controllerName, object values)
      {
        UrlHelper urlHelper = new UrlHelper(context);
        string url = urlHelper.Action(actionName, controllerName, values);
    
        Url = url;
      }
    
      public PermanentRedirectResult(RequestContext context, string actionName, string controllerName, RouteValueDictionary values)
      {
        UrlHelper urlHelper = new UrlHelper(context);
        string url = urlHelper.Action(actionName, controllerName, values);
    
        Url = url;
      }
    
      public override void ExecuteResult(ControllerContext context)
      {
        if (context == null)
        {
          throw new ArgumentNullException("context");
        }
        context.HttpContext.Response.StatusCode = 301;
        context.HttpContext.Response.RedirectLocation = Url;
        context.HttpContext.Response.End();
      }
    }
    

    Usage in the action

    //Just passing a url that is already known
    return new PermanentRedirectResult(url);
    
    //*or*
    
    //Redirect to a different controller/action
    return new PermanentRedirectResult(ControllerContext.RequestContext, "ActionName", "ControllerName");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Designing a new system from scratch. I'll be using the STL to store lists
I am designing a new System and I have a lot of Interfaces that
When designing a new J2EE based enterprise framework, do I have to prepare for
I'm designing a new newsletter which looks great in Opera, Firefox and Chrome, but
I'm designing a new site for a local government department in Scotland and I
I am designing a new laboratory database. I want all the raw results (for
I have an existing WinForms application for which I'm now designing new bits in
I have this task of designing a new interface for a distributed application (multiple
I am new to designing interfaces for Android. (I have gone through the Multiple
When designing a new Crystal Report you have to create a new database connection.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.