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 4535816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:27:12+00:00 2026-05-21T14:27:12+00:00

In my Asp.Net Mvc project I’d like to have a good looking urls, e.g.

  • 0

In my Asp.Net Mvc project I’d like to have a good looking urls, e.g. mysite.com/Page2, and I want to redirect from my old style urls (such as mysite.com?page=2) with 301 state so that there won’t be two urls with identical content. Is there a way to do it?

As far as I know Asp.Net binding framework doesn’t make difference between query string and curly brace params

  • 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-21T14:27:12+00:00Added an answer on May 21, 2026 at 2:27 pm

    Well, as far as I can see performing such redirection in ASP.NET MVC might be tricky. This is how I did it:

    global.asax:

            routes.Add(new QueryStringRoute());
    
            routes.MapRoute(null, "Article/{id}/{name}",
                new { controller = "Article", action = "View", page = 1 },
                new { page = @"\d+" }
            );
    
            routes.MapRoute(null, "Article/{id}/{name}/Page{page}",
                new { controller = "Article", action = "View" },
                new { page = @"\d+" }
            );
    

    QueryStringRoute.cs:

    public class QueryStringRoute : RouteBase
    {
        private static string[] queryStringUrls = new string[]
        {
            @"~/Article/\d{1,6}/.*?page=\d{1,3}"
        };
    
    
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            string url = httpContext.Request.AppRelativeCurrentExecutionFilePath;
    
            foreach (string queryStringUrl in queryStringUrls)
            {
                Regex regex = new Regex(queryStringUrl);
                if (regex.IsMatch(url))
                {
                    long id = 0; /* Parse the value from regex match */
                    int page = 0; /* Parse the value from regex match */
                    string name = ""; /* Parse the value from regex match */
    
                    RouteData rd = new RouteData(this, new MvcRouteHandler());
    
                    rd.Values.Add("controller", "QueryStringUrl");
                    rd.Values.Add("action", "Redirect");
                    rd.Values.Add("id", id);
                    rd.Values.Add("page", page);
                    rd.Values.Add("name", name);
                    rd.Values.Add("controllerToRedirect", "Article");
                    rd.Values.Add("actionToRedirect", "View");
    
                    return rd;
                }
            }
    
            return null;
        }
    
    
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            return null;
        }
    }
    

    QueryStringUrlController.cs:

    public class QueryStringUrlController : Controller
    {
        public RedirectToRouteResult Redirect(long id, int page, string name,
            string controllerToRedirect, string actionToRedirect)
        {
            return RedirectToActionPermanent(actionToRedirect, controllerToRedirect, new { id = id, page = page, name = name });
        }
    }
    

    Assuming you have such routing as in my global.asax file (listed above) you can create a custom Route class that will handle incoming requests and map them on a special redirection controller which will then redirect them to appropriate urls with 301 state. Then you must add this route to global.asax before your “Article” routes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using T4MVC in our ASP.NET MVC project. I have a statement like
I have a ASP.NET MVC project, and I would like to have a different
I have an ASP.NET MVC project containing an AdminController class and giving me URls
I have this ASP.net MVC project that requires a wizard like interface... So I
In my ASP.NET MVC project I have added a parameters.xml file that looks like:
I have an ASP.NET MVC project that I would like to unit test. Most
I have a ASP.NET MVC project and i want to use jQuery on them.
In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated
I have a new asp.net mvc project and i am trying to figure out
I have an ASP.NET MVC project with xVal and data annotations and I need

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.