Upgrade classic ASP to MVC 4.0 - asp.net

I'm in the process of upgrading from classic ASP to MVC 4.0. MVC projects have a unique folder structure with modules, views, and controllers. Our classic ASP website is very well indexed in search engines, and uses all friendly URLs (some mapped to existing folders and removing page extensions, and others mapped for SEO and not to the folder containing the files), using Rewrite Rules in web.config. I need to maintain all the current URLs, but they all map into different folders than the MVC project will. I'd like the MVC project to remain in the folder structure defined in the default project, but also need to continue using the existing URLs.
What is the best way to maintain the current URLs of the site when moving to MVC? Is custom routing the only/best way to handle this?

I gues there are four ways to do rewriting urls, no matter which one you use, you need to do some changes. For example you should change the way you read the url parameters.
I follow this tutorial http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
It helps alot

Related

Allow HTML files in Asp.Net MVC application

I'm building an application using ASP.NET MVC and Angular JS.
The point is to use angular for all web things and ASP.Net for backend stuff. In other words, I kind of bypassed the whole view of MVC and used a single view. Angular will get his files from the Content folder.
Those files are .html files and this seem to be a problem because I always get a 404.
Actually I also tried renaming it to .cshtml but that does not fix the problem..
Do you know of any tricks (well, clean ones of course) to let my angular app download it's views and be happy?
Thanks.
Georges
The problem most likely is in the fact that ASP.NET MVC tries to filter the request through the routing mechanism, and obviously there is no route for HTML files. Try adding the following to the routes registration method:
routes.IgnoreRoute("{file}.html");

Orchard CMS (Asp.Net MVC) integration like additional area

Is possible to integrate orchard to existing Asp.Net MVC3 site like separate area?
Like this:
Web.proj
View
Controllers
Models
BackendArea
OrchardCMS files
As a result Orchard CMS will be using for storing resources (strings, images ets.) of main site and easy to manage resources.
Problems:
I don't whant to use virtual folders
on IIS.
Orchard CMS used own Global.asax,
web.config, earlier version of
NHibernate and different
IOC(Spring.net is used for main site)
Given the architecture of ASP.NET, not really or at least not cleanly. From what it sounds like, you are really just trying to use the HTTP interface of orchard in a sub-uri, which is possible by setting up a reverse proxy and forwarding requests to a different app living on a different site. See carlosag's article for a basic overview. Here are some protips:
make sure you ignore the route you are going to reverse proxy -- you don't want ASP.NET mvc kicking in and trying to route it.
Use a virtual directory on the main site where you are reverse proxying. This is where you setup the url rewrites and such.
Setup the orchard "site" running in a virtual directory under your fake site with the same name as your virtual directory -- helps fool IIS into building URLs correctly.
The other way around will be a lot more likely to succeed. What you describe was a non-goal for Orchard.

How to create a blog in ASP.NET and not ASP.NET MVC

I have created a blog application with ASP.NET MVC and MSSQL. I must say, i really enjoyed the process of creating an application with ASP.NET MVC. Clean URLS(with URL routing), No view States and so on.
BUT i was wondering how would this would have been done if i choose web-form style coding? will the aspx would be created in the fly as i create a article.(take this url for ex: http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx) though the URL is not clean but still makes sense. if yes then what about its corresponding cs file? if no how is the URL so clean?
Would be great if someone throw some light on how it is done in ASP.NET.
Thank you, Faraaz.
If your using .NET 4, you can make use of MapPageRoute to accomplish the clean URL's with regular Web Forms.
routes.MapPageRoute("MySuperCleanRoute", "some/clean/url", "~/ActualPage.aspx");
With the addition of MapPageRoute, you no longer have the feeling "I should use ASP.NET MVC because i want clean URL's".
Choose ASP.NET MVC if you like the pattern. If your used to Web Forms, use it - and use MapPageRoute to achieve clean URL's (or use a URL Rewriting module if <= .NET 4)
A blog in ASP .NET would have been done in much the same way. The idea is to use one file and URL rewriting. IIS7 has URL rewriting built in but for IIS6 you can use something like ISAPI_Rewrite to handle .htaccess style files (which is what Apache uses).
ASP .NET MVC handles all this for you in its routing but you can do it yourself using a URL rewriting tool. The difference is that for MVC, the application handles the rewriting but ISAPI_Rewrite, IIS Rewriting are done by the server. This can change a URL like http://mysite.com/something/other to http://mysite.com/file.asp?p1=something&p2=other.
The second link is only internal to the server (it doesn't actually change the URL in the user's address bar). In the case of a URL like on Scott's blog, you could store the 'announcing-nupack-asp...' bit in a database as part of the article row so your blog article page has something to look for. The files don't actually exist on the server but the rewriting passes all requests to an existing file with parameters.
Note that this technique is common for lots of different sites - not just blogs. Notice the Stack Overflow URL, Twitter URLs, etc.
MSDN has an old article on URL Rewriting in ASP .NET, along with some examples of filters you can use.
See IIS URL Rewrite Module
You can use the URL Rewriting that is in asp.net MVC with WebForms if you are using .Net Framework 3.5 SP1 (if you don't have access to .Net 4)
Here's an MSDN magazine article explaning...

Having URL without .aspx extension

I noticed a lot of ASP .Net sites does not have the URL ending with ".aspx".
An example would be:
- https://stackoverflow.com/questions
Did they create a Questions folder and put a Default.aspx inside?
In that case, wouldn't there be A LOT of default.aspx in many folders which is hard to maintain (even though it is user-friendly)?
Thanks y'all.
StackOverflow is written using ASP.NET MVC. The MVC framework does not use .aspx files.
The way it works internally is by using routing tables - see an overview here.
You can also do this with ASP.NET and .aspx files or you can use URL rewriting. You can read about the differences here.
You can refer to any URL rewriter or a routing technique for that. If you look at the new AS{.NET MVC, it works on that model only.
You can use Url Rewriter to remove extensions from the urls of your website.
ASP.net has a routing framework you can use even if you are not using ASP.net MVC
Official documentation: http://msdn.microsoft.com/en-us/library/cc668201.aspx
Also as previously stated ASP.net MVC works like this out of the box and you can also use URL Rewriting
With ASP.NET 4.0, you get the benefits of URL routing (nice, clean URLs) with ASP.NET webforms, too — see:
Routing for Web Forms in ASP.NET 4.0
URL Routing with ASP.NET 4 Web Forms (VS 2010 and .NET 4.0 Series)
Basically, what you do is define a route like
/question/{id} or /question/{title}
and you then define what ASPX page this is being routed to. Quite nifty!

How could I use ASP.NET MVC framework in conjunction with my CMS software?

I have been reading on MVC and I created some db-driven pet projects with it and I am very pleased with the shift from WebForms.
However, I have a bit of a limitation that holds me back with WebForms and I was wondering if you could help me with it.
I work for a Web CMS company as a Consultant, therefore all websites (public sites, intranets, extranets, you name it) are based on the CMS software from my company (which should remain nameless).
One of the features that the sales guys like to pitch about our software is its "friendly" urls. Baiscally all data is stored and structured within the CMS like a file system. Then when you point your browser to http://mywebsite.com/about the CMS will return the contents from the item stored under the root with the name "about".
Each item also has a (interchangeable) template registration which is the physical location of the file that is going to display the contents of it (an .aspx page). Just like the "Views" on MVC.
To handle the friendly URLs I have to add a HTTP Handler as follows:
<add verb="*" path="*"
type="Cms.ASPDelivery.HttpRequestHandlerFactory, CmsDelivery" />
That will take care of the friendly URLs and will do the mapping between contents and views.
In an architectural way you could see that just like MVC. The data is stored in the CMS, the presentation is independent of the data, and the handler will be the Controller.
But when it comes down to coding in itself, it is the same old Webforms spagetti.
So, my question is: Do you see any way that I could use both MVC and my CMS' Http Handler?
It depends on the concrete Implementation of the HttpHandler but in most cases it is possible. You have to add the MVC UrlRoutingModule and setup the MVC. I use MVC in a CMS environment with friendly url-s. The CMS is called EPiServer and from what you described it has pretty much the same functionality. I use ASP.NET MVC for the template pages. The path to the physical pages is actually handled by controllers' actions. It works fine and with some tweaking I can say that it is a lot better than WebFroms especially if you develop custom web applications.

Resources