开发者

Moving from Classic ASP to ASP.net [closed]

Closed. This question is opinion-based. It is not currently accepting answers. 开发者_运维知识库

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 2 years ago.

Improve this question

I've come from a Classic ASP background, done it for years and years and moving to .net has been way overdue, so I've started to learn .net.

It's very different to say the least! It's structured a lot differently, and seems to work a lot differently, it's a huge leap upwards. However, it is appearing to me to be more and more awesome.

I've had a quick search and can't find any similar questions, so I've created this one as a community wiki, if you could list the pitfalls/differences or whatever you think it relevant in your responses it might be helpful to a lot of people.

So in summary, what are the main differences/gotchas moving from Classic ASP to ASP.net? (c# or VB.net). Please don't just list language features of .net, it needs to be in the context of someone moving from one to the other.


I'm assuming that you are moving to WebForms (but you might consider to jump straight to MVC or Silverlight as WebForms is on its way out)

FWIW when I made the move the following were probably the main gotchas:

  • Resist the temptation to use classic conventions <%=, #include
  • Resist the temptation to edit the ASPX file by hand - try to just use the designer
  • You will need to get up to speed with OO if you haven't done so already
  • For WebForms, you will need to take a VB6 / WinForms approach to button handlers etc
  • Use the ASP.NET controls - you won't need to fuss about micromanaging the state of controls as you did in ASP Classic

Take in some videos: http://www.asp.net/general/videos#Videos%20on%20Migrating%20to%20ASP.NET


I did the same thing quite a few years ago. I can't say I found any “pitfalls”; in fact quite a lot of the annoying thngs that always used to catch me out in classic ASP just disappeared when I moved on to ASP.NET.

I think the biggest difference was moving from ASP/JScript to strongly typed C#. It forced me to be less lazy when declaring variables and as a result I encountered far less bugs relating to scope or data type conversion. Writing reusable, object oriented code is also much easier in C#.

If you're just getting into it, I would advise you (and this is just my opinion) to steer well clear of ASP.NET Web Forms and just jump straight into MVC. It takes a while to readjust your brain to work in the MVC paradigm, but once it “clicks” it all just makes total sense.

We recently got this book at my office, and I thoroughly recommend it; don't let the “Pro” bit put you off, it starts right from the basics and was very plain and easy to understand.


There are a bunch of useful articles available at your favourite search engine. You will need to answer some questions for yourself to start with (http://www.google.co.uk/#hl=en&source=hp&q=transition+from+asp+to+asp.net&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=a53e9ae07f1cc2a8)

Are you going to use ASP.NET Web Forms or ASP.NET MVC? This blog has a good article on the difference (http://weblogs.asp.net/shijuvarghese/archive/2008/07/09/asp-net-mvc-vs-asp-net-web-form.aspx). Both have value for their purpose.

Are you going to try and port your existing code or make a clean break?

Razor is a new syntax for ASP.NET which I highly recommend. It gives a very natural feel to combining html and c# code syntax. This blog (http://blogs.msdn.com/b/davidebb/archive/2010/07/07/how-webmatrix-razor-asp-net-web-pages-and-mvc-fit-together.aspx) has a good post on one of the latest stack for MS including Razor.

Learn object oriented programming. It is pretty crucial.

Got to http://www.asp.net it is a great resource. use the tutorials and read other peoples code.

EDIT: I forgot to mention, if you are going to focus on ASP.NET WebForms please learn the page life cycle as not understanding this leads to a common class of bugs around dynamic controls. http://msdn.microsoft.com/en-us/library/ms178472.aspx


When I started in Classic ASP I hadn't had any other programming experience. I hadn't ever built anything in windows forms or console applications. So, when I moved to asp.net, it took me a while to figure out what the heck was going on with code behind and control event handlers. In my first few projects I was trying to code like a Classic ASP programmer. I would do silly things along the lines of...

public void Page_Load(object sender, EventArgs e) {
    if (Request.ServerVariables["REQUEST_METHOD"] == "POST") {
      string myHtmlOutput = "";
      string firstName = "";
      if (Request.Form["ctl0_MainContent_FirstName"] != null) {
        firstName = Convert.ToString(Request.Form["ctl0_MainContent_FirstName"]);
        myHtmlOutput = "<h1>Hello "+ firstName +"</h1>";

        Response.Write(myHtmlOutput);
      }
    }
}

Instead of the WebForms way...

public void Button1_Click(object sender, EventArgs e) {
    if (!string.IsNullOrEmpty(FirstName.Text)) {
      MessageLiteral.Text = string.Format("Hello {0}", FirstName.Text);
    }
}

I honestly think that if asp.net MVC had been around when I moved from Classic ASP, I would have had an easier time getting the hang of it because I wouldn't have had to spend so much time learning all of the asp.net abstractions.


Includes

Good design from Classic ASP comes from using include files to modularise your code.

In .net, this is not possible in the same way as it is based on an object orientated hierachy.


If you are jumping into Webform, then read up and learn about ASP.NET's ViewState; how a page persists across post backs. If you are going to dabble in ASP.NET MVC, read about Model View Controllers. In either framework, ASP.NET is an object oriented language where classic is not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜