Friday, May 21, 2010

How to migrate from ASP to ASP.NET

If you are using ASP, it is still not too late for you to migrate into latest ASP.NET. If you are worrying about the effort and the time for migration let me share with you my experience which may save you significant time and help you to migrate your project.

  • To start with you need to have Microsoft Visual Studio 2003. 
  • Install ASP to ASP.NET migration Assistant tool from http://www.asp.net/downloads/archived-v11/migration-assistants/asp-to-aspnet
  • After installing it, inside Visual Studio you will find a new option available under File -> Open -> Convert. Please go through this link http://www.asp101.com/articles/john/asptoaspnet/default.asp
  • Run this tool on your project completely, kindly note that your application will be converted using VB.NET language only. If you want to use C# language, you can find plenty of online converters. But it would be ideal to use VB.NET since it is syntactically almost same as ASP. 
  • Now let me tell you one of the major problem you may face. After converting your project completely to ASP.NET you would like to compile it to make it run and to your surprise you will end up getting hundreds of errors. Most of the errors would come due to your ASP style of coding in which  developers try to use many variable as global and share them across the asp pages. Since ASP is an interpreted language so if any used variable is available at runtime it won't yell. ASP.NET being a compiled language needs all variables or methods to be available at compile time.
  • To overcome the nightmares that came due to difference in interpreted vs compiled language processing, we used following methodology
    • All ASP pages which were included inside other ASP pages but were not used in showing UI. We renamed their extensions to .inc. This way ASP.NET compiler will ignore all pages with .inc extension and they will be included within your aspx page as if they were in ASP. Let me go into more details suppose you had a.asp & b.asp which were using a helper page c.asp. Now if a.asp is using some variable which is declared in c.asp or c.asp is calling a method which is declared in b.asp, after conversion and compilation you will get build error from both a.aspx and c.aspx. ASP.NET will try to compile each individual .aspx page and it will create a dynamic class and put all your code (inside script tag) within that and then try to compile. It will expect that your class (code inside script tag) has all dependency available which is essentially not there in our case. When we rename our c.aspx to c.aspx.inc and include it inside a.aspx and b.aspx. ASP.NET compiler will not compile c.aspx.inc separately but when it will go compiling a.aspx and b.aspx it will include c.aspx.inc code in that (as if they were part of those pages) and now a.aspx and b.aspx both will get compiled.
    • We made sure that there should not be any .inc file inside a .inc file. You have to put all dependency/include file of a UI page (aspx) within that page. This will prevent you the problems coming due to multilevel nesting of files and cyclic dependency. But it is all upto you, you may keep your ASP like structure as it is and yet make it run.
    • .inc file should not have any variable declared inside the file. We moved all the variables from .inc file to the page where .inc file is included. This way every page had its own contained local variables and there is no conflict with other pages. You may create another inc file which can include all variables used inside your any of inc and insert that file on every aspx page. This is again upto you how you want to implement it.
    • If a method is used in an inc file which is defined in another inc file but the second inc file was originally not included in your ASP page (now aspx) then just for the heck of preventing the compilation error don't include the "not required" inc file (basically try to maintain the same file include structure as you had in your ASP application). We initially started including the inc files which were not originally part of ASP page and ended up including almost all the inc files. To prevent compilation error, you need to create stub method/variable. for e.g. if a method Public Sub Test()  ... end Sub is causing this issue because it is implemented inside an inc file which was not included originally in your ASP page, then you just need to declare an object in you UI page as following Public Dim Test As Object. That means your aspx page (which is essentially a class) should have implementation of only those methods which are actually used inside it. If compiler is crying for some method which is actually not used inside your page but compiler needs it because of some dependency issue, you just create an empty implementation of that sub/function (instead of including a file where that method is implemented).
    • If the above mentioned method Test takes some arguments then you can provide a stub implementation of that as well for e.g. Public Sub Test (arg1 , arg2) 'no implementation End Sub. that is still better than including the complete file just the heck of stopping compilation error.
    • You may come across some object assignment issues. Please read this to know how to fix them http://aspnettechstuffs.blogspot.com/2010/05/how-to-assign-one-object-to-another-in.html
    • If you are using COM, you may need to fix few more things, read it  http://aspnettechstuffs.blogspot.com/2010/05/vbnet-to-interop-com-dll-call-failed.html
  • You will initially convert your project compatible to framework 1.1. Then after you have to follow a vertical development or horizontal whatever suits to your development cycle and slowly include all the best practices and coding guidelines. 
  • Since .net provides backward compatibility, you can use the same project in framework 2.0 and later slowly enhance it.
  • Read my small presentation to know the need of migration http://docs.google.com/present/edit?id=0AW5WT4_yjBDJZGdia3pqN2RfMWN0MzJybmY4&hl=en
If you get stuck somewhere, please write me a mail. I would try my best to resolve you query.
I strongly recommend to get out of ASP and use ASP.NET. you have to invest some time initially but later you will get immense benefits and a highly scalable application.


7 comments:

  1. Thank you very much for such knowledgeable and sincere help, this can come only from an expert.
    Your sincerity is greatly appreciated.

    ReplyDelete
  2. Hi, I am a newbie in ASP and / ASP.net. I want to know, is it possible to convert an ASP project to ASP.net using Visual Studios 2008 instead of 2003? I only have 2008 currently and I am doing research on how to do it - of course without having to write the code completely over again, and seem to not have seen any light as the articles that I found is using VS 2003. I tried exploring my VS 2008, but I did not see any convert options.
    Thank you very much.

    ReplyDelete
  3. Hi Lim, thanks for visiting my site.

    You can run same migration assistant from command line as well
    http://www.asp.net/downloads/archived-v11/migration-assistants/asp-to-aspnet/overview

    You may also look at http://www.artinsoft.com/so_asp.aspx
    but mindful of artinsoft license cost.

    ReplyDelete
  4. Hi Abhishek,

    Thanks for your prompt reply..
    I have tried the first one, but to no avail. Perhaps I got the code wrongly.

    I tried the command that were 'instructed', changed the , tried to put ' " " ' in between the path where there's a space, but still wrong. Could you be kind so as to help me out? Perhaps I was missing a step?

    And, the code below is what we have to write in the command right?

    I really appreciate your help. :)

    Have a good day.

    ASPUpgrade[.exe] [/Out ] [/NoLog | /LogFile ] [/Verbose] [ /ProjectName ] [/ForceOverwrite]

    ReplyDelete
  5. Great tips for asp to asp.net migration.

    ReplyDelete
  6. INTERNATIONAL CONCEPT OF WORK FROM HOME
    Work from home theory is fast gaining popularity because of the freedom and flexibility that comes with it. Since one is not bound by fixed working hours, they can schedule their work at the time when they feel most productive and convenient to them. Women & Men benefit a lot from this concept of work since they can balance their home and work perfectly. People mostly find that in this situation, their productivity is higher and stress levels lower. Those who like isolation and a tranquil work environment also tend to prefer this way of working. Today, with the kind of communication networks available, millions of people worldwide are considering this option.

    Women & Men who want to be independent but cannot afford to leave their responsibilities at home aside will benefit a lot from this concept of work. It makes it easier to maintain a healthy balance between home and work. The family doesn't get neglected and you can get your work done too. You can thus effectively juggle home responsibilities with your career. Working from home is definitely a viable option but it also needs a lot of hard work and discipline. You have to make a time schedule for yourself and stick to it. There will be a time frame of course for any job you take up and you have to fulfill that project within that time frame.

    There are many things that can be done working from home. A few of them is listed below that will give you a general idea about the benefits of this concept.

    Baby-sitting
    This is the most common and highly preferred job that Women & Men like doing. Since in today's competitive world both the parents have to work they need a secure place to leave behind their children who will take care of them and parents can also relax without being worried all the time. In this job you don't require any degree or qualifications. You only have to know how to take care of children. Parents are happy to pay handsome salary and you can also earn a lot without putting too much of an effort.

    Nursery
    For those who have a garden or an open space at your disposal and are also interested in gardening can go for this method of earning money. If given proper time and efforts nursery business can flourish very well and you will earn handsomely. But just as all jobs establishing it will be a bit difficult but the end results are outstanding.

    Freelance
    Freelance can be in different wings. Either you can be a freelance reporter or a freelance photographer. You can also do designing or be in the advertising field doing project on your own. Being independent and working independently will depend on your field of work and the availability of its worth in the market. If you like doing jewellery designing you can do that at home totally independently. You can also work on freelancing as a marketing executive working from home. Wanna know more, email us on workfromhome.otr214423@gmail.com and we will send you information on how you can actually work as a marketing freelancer.


    Internet related work
    This is a very vast field and here sky is the limit. All you need is a computer and Internet facility. Whatever field you are into work at home is perfect match in the software field. You can match your time according to your convenience and complete whatever projects you get. To learn more about how to work from home, contact us today on workfromhome.otr214423@gmail.comand our team will get you started on some excellent work from home projects.


    Diet food
    Since now a days Women & Men are more conscious of the food that they eat hence they prefer to have homemade low cal food and if you can start supplying low cal food to various offices then it will be a very good source of income and not too much of efforts. You can hire a few ladies who will help you out and this can be a good business.

    Thus think over this concept and go ahead.

    ReplyDelete