Maintaining old URLs after revamping ASP.NET web site - asp.net

There is an ASP.NET 2.0 web site that I intend to migrate to a new web framework based on ASP.NET 4.0. While I know this involves manually preparing a script/program to transform site's content from old application's database schema to the new one, I am more concerned about preserving the old URL formats; mapping them to the new web engine's URL format.
I have not yet decided what is the most appropriate CMS engine to migrate towards (thus Web forms or MVC is still not clear). However, I'd like to draw on everybody's experience on
general issues to look out for (regardless of web application platform)
candidate strategies/techniques to handle the URL remapping in ASP.NET
Google Analytics is already configured for the web site, so there is a history of the most requested links to study - which are the most important URL formats to remap and which are not worth preserving.
Due to work areas i've been diverted to the past few years, I've not been able to keep up with the latest ASP.NET capabilities that can help with this. Oddly, I find little material discussing how to properly preserve old URLs; most web sites are pretty nasty in totally discarding their old links when they perform a design overhaul.
My first thought of the most straightforward technique is just to specify in web.config a custom 404 aspx page that will read the old requested URL (which will carry the original content ID). Based on the content ID, look up a custom database table to find the new content ID, and redirect with the new URL.
At this point I am unsure if I'd want to make use of URL rewriting HttpModule or extension because I'd only want to incur the "lookup" only when it becomes 404, rather than a check on each and every request. Knowing that old URL requests will eventually fade over time.
What other factors/aspects should I consider?

For SEO performance, it's not really a good idea to issue a 404 or a 302 if you want to maintain good link value for each page you should issue a 301, a permanent redirect which search engines will use to pass any link equity to the new url.
With MVC you could register your old urls to a route that uses some form of dedicated RedirectController, something like:
public class RedirectController : Controller
{
public ActionResult RedirectArticle(int articleId)
{
string newUrl = // do something to figure out the new url, e.g. http://localhost/article/1 -> http://localhost/1/my-custom-article-url
return RedirectPermanent(newUrl);
}
}
That way, you can register routes to support both the old infrastructure and the new, with a RedirectController issuing the appropriate page-specific 301 redirect to the new page.
routes.MapRoute(
"NewArticleUrl",
"/{articleId}/{articleTitle}",
new { controller = "Article", action = "Display");
routes.MapRoute(
"OldArticleUrl",
"/article/{articleId}.aspx",
new { controller = "Redirect", action = "RedirectArtciel" });

Related

Adding simple CMS functionality to an existing MVC application

ASP.NET 4.51, MVC 5
Have read Integrating a CMS into an established application-centric MVC website
We have a number of MVC applications that serve as public facing websites. The applications were built using MVC as that was the technology stack understood by the developers and primarily the content that was being delivered was based on business process data.
However more and more we are being asked to add "another page" to the websites which for all intents and purposes is a plain old static content page. This ultimately involves:
Adding a new route
Creating a view with the required HTML
We have various "home grown" solutions which now pull HTML from the database for these views. However this means we are writing custom back end data entry screens as well as 1 & 2 above.
So.... There must be a better way. Has anyone got any practical experience or suggestions on how to add simple CMS functionality that we can give to end users, plugged into our MVC application? We need to provide the following functionality to the end user:
Create new pages, edit pages using WYSIWYG
Add meta tags and canonical tags for SEO
Specify the url portion of the uri for SEO purposes
All insights appreciated.
Is it feasible to do the following:
Have a database table to house the content for these pages. e.g. title, summary, description, url, meta, image(s) etc...
In the front end have a template for these pages. The database data fills in the placeholders within this template.
Perhaps hold all the pages on a base URL like www.yoursite.com/page/dynamic-page-url-from-db
You can use the Remote attribute validation on the url field to make sure they are all unique in the database.
With this in mind, create a single Route to catch the requests and filter valid/invalid requests in the Page controller based on the URL provided with the db. If non-existent throw new HttpException(404, "Page Not Found"); and have an error handler pick that up and deliver your 404.
META could be set via ViewBag or a dedicated section that alters the _Layout file at the point of rendering the view.
TinyMCE is a decent WYSIWYG editor. You can even add dynamic image gallery functionality to it if you want to embed images within the main body of the pages.
I'm working on making a CMS currently used in a demanding production environment into a product. I've just (as of 20 Jan 2015) made a NuGet package which installs the CMS into an MVC project which should be possible to add to any existing MVC site without breaking it. CMS functionality can then be added where needed. Currently I'm looking to work with some users to help them get the CMS into production on their sites, however this may have changed by the time you read this. Look at http://www.lynicon.com for more information and to sign up to a Slack community where I can give you access to the NuGet package.

ASP.NET Web Forms URL Rewriting capability

I have a very simple question, rather I am just curious.
I have about 2000 pages of the url format somewebsite.com/ShowProduct.aspx?ID=223 . This particular url has a page title as 'Walking sticks for elders made from durable steel'.
Can I use URL Rewriting to convert this to a url like somewebsite.com/walking-stick-for-elders ? Also will I have do it dynamically for 2000 pages or is there any expression that can be used?
You need to have some thing which uniquely indentifies URLs just like Stackoverflow does it.
ASP.NET Web Forms URL Rewriting capability
See this question URL - Where from URL you get its for question then there is a question id and then description. I suggest you do the same.
If you are using ASP.NET 4.0 or higher version then you can do that type of URL routing very easily.
Like from this URL - http://weblogs.asp.net/scottgu/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series
There is also a asp.net friendly URL package form where you can write URls.
http://www.hanselman.com/blog/IntroducingASPNETFriendlyUrlsCleanerURLsEasierRoutingAndMobileViewsForASPNETWebForms.aspx
RouteConfig.RegisterRoutes(RouteTable.Routes);
If each product name is unique and stored inside the database you can easily route each SEO friendly URL to productID without manually inputing a new route in the Routing table.

Get Tridion URI from a Page Publish Path?

I would like to get a Page URI from the Tridion Page PublishPath (URL from public site).
I know I can use the WebDavURL to get the Page - but there are many cases where this does not match the Page Path (such as the case when the Page Filename is 'News Home' but the filename is 'index').
I currently do not think this is possible in Tridion and have thought about the following solutions:
Store the Page Publish Path in the Tridion Solr Index (by extending it)
Customized Tridion Search Index Handler: Custom vs Standard field for page url?
Use the Event System and persist the PublishPath and Uri to an external DB / KeyValueStore.
Other ideas?
This code would be used in a script that updates many pages but also for Editors to open a Page using the Page URL.
This may be considered an odd approach, but could you query the Broker to get the PageMeta by URL, and then you will be able to access the the URI from the PageMeta object?
Just a thought - but it is probably not ideal - Can you share some more background on the problem?
I'm assuming you need to do this CME side? Is performance a factor?
You could build a function in Tom.net or the CoreService to split the path you have and loop through the sgs and pages till you arrive at the correct content page. As long as the path information hasn't been changed since the page published, this should map together.

How can I redirect a user to a new page in IIS based upon the URL

I have a web app that opens certain projects based upon a projectID
So ID 12345 = project foobar
http://my.example.com?projID=12345
However I would like to provide a different site that doesnt require the projectid, and is easier to remember for the end user.
So if a user visits
http://simple.example.com/foobar (note this is a different site, though I suppose we could put this in the same site if easier)
They would automatically get redirected to
http://my.example.com?projID=12345
Obviously I would want a system where I could have more entries than just foobar
if you don't want to use the rewrite module mentioned above you could always do it yourself by implementing a custom 404 handler and key off aspxerrorpath or perhaps putting the code in a custom httpHandler.
We actually do this with in one of our applications. We use a cms system to specify all of the redirects so nothing is really hard coded and marketers and SEO teams can handle it without our help.
in my opinion you should use ashx to handle web request. here is very simple and beautiful example of what you are looking for :-
http://www.dotnetperls.com/ashx

One custom handler for different request url's in ASP.NET web site

I am doing a small ASP.NET 2.0. site refactoring.
Currently there is the following folder structure:
/siteroot/services/home/service1
/siteroot/services/home/service2
/siteroot/services/home/service3
...
all the folders (service1, 2, 3) contain an almost identical default.aspx, with the different content hardcoded into the web form declaration.
My idea is to create one service.aspx and serve custom page (with the same template) on a particular URL request.
My question is:
How can I redirect all request to ../services/home/service1,2,3 to one particular handler/aspx page?
Preferably not to have those folders in the project structure at all, but intercept a requests that are headed to them.
If you are able to implement ASP.NET 3.5 (runs on the 2.0 CLR), then Routing sounds perfect for what you need to achieve. With this you can intercept URLs based on a particular format and then route them through to a single page or handler. You won't need a folder structure for each of your services.
Here's a few links on how to get going with it in ASP.NET WebForms. It's pretty quick to implement:
http://msdn.microsoft.com/en-us/magazine/dd347546.aspx
http://msdn.microsoft.com/en-us/library/cc668201%28v=VS.90%29.aspx
http://haacked.com/archive/2008/03/11/using-routing-with-webforms.aspx
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
One way:
Create a custom handler class that implements IHttpModule
In Init(HttpApplication application), register a method for application.AuthorizeRequest
In this method, parse ((HttpApplication)sender).Request.Path as appropriate, using HttpContext.Current.RewritePath if necessary to point to a "real" service.aspx page.
Then register your custom handler in <system.webServer><modules>.
Another way is to use the MVC-style routing, which works without MVC just fine. Details are in the answer to the question here: custom URL Routing in asp.net.

Resources