4

I was working on a Website which was earlier built with ASP.NET Web Forms and now is built with ASP.NET MVC.

We made the new MVC version live last week.

But the old login url which is www.website.com/login.aspx has been bookmarked by many users and they still use that and hence they get 404 errors.

So I was wondering which would be the easiest and best way to redirect the user from the old url to the new mvc url which is www.website.com/account/login

Like this login url, I am expecting the users may have bookmarked few other urls also, so what will be the best way to handle this ?

4
  • why not keep the old page and redirect from it. web forms and mvc routes can go-exist in the same project... Commented Apr 1, 2013 at 4:57
  • Have removed the old project completely Commented Apr 1, 2013 at 4:58
  • you can check url in global.asax file...if url is www.website.com/login.aspx then you can redirect user to www.website.com/account/login Commented Apr 1, 2013 at 5:09
  • Is this a URL thing or just a rogue page that got favoritized? if the second, recreate a webforms page (login) as well as any other favored potentials and have them redirect to latest-and-greatest... Commented Apr 1, 2013 at 5:13

2 Answers 2

6

You could use the URL Rewrite module in IIS. It's as simple as putting the following rule in your <system.webServer> section:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Login page redirect" stopProcessing="true">  
                <match url="login.aspx" />  
                <action type="Redirect" redirectType="Permanent" url="account/login" />  
            </rule>  
        </rules>
    </rewrite>

    ...
</system.webServer>

The module is very powerful and allows you any kind of rewrites and redirects. Here are some other sample rules.

Sign up to request clarification or add additional context in comments.

Comments

5

in the global.asax

void Application_BeginRequest(Object source, EventArgs e)
    {
        //HttpApplication app = (HttpApplication)source;
        //HttpContext context = app.Context;

        string reqURL = HttpContext.Current.Request.Url;

        if(String.compare(reqURL, "www.website.com/login.aspx")==0)
        {
            Response.Redirect("www.website.com/account/login");
        }
    }

2 Comments

you can implement other logic to match the url as well
Awesome i use this to do 301 redirects that are needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.