asp.net key considerations(一)从前用惯了asp的朋友看看这个吧,大家常问的如Request等问题解答得很清楚

asp.net|request|解答|问题

Migrating to ASP .NET: Key Considerations

Jim Kieley
Microsoft Corporation
July 2001
Summary: This article explores some basic considerations for moving existing ASP applications to the ASP .NET environment as quickly and efficiently as possible. (18 printed pages)

Contents

Introduction
Compatibility Issues
Core API Changes
Structural Changes
Visual Basic Language Changes
COM-Related Changes
Application Configuration Changes
State Management
Security-Related Changes
Data Access
Preparation for ASP .NET
Summary Introduction
Although the designers of Microsoft ASP .NET have done an excellent job in preserving backward compatibility with ASP applications, there are a few key items you need to be aware of before undertaking the effort of moving a Web application from ASP to ASP .NET. A solid understanding of the technologies that have changed or been introduced with the .NET platform and ASP .NET will go a long way in making this process a whole lot easier.
This article explores a number of areas of change to give a clear understanding of the efforts involved in getting an ASP application up and running in the ASP .NET environment. At the same time, it points out some of the new features of ASP .NET that can be leveraged to improve an existing application. This is by no means a comprehensive look at all of the new features in ASP .NET. Instead, it focuses on areas that you need to know now for successful migration.
I am assuming that since the majority of ASP applications use Microsoft Visual Basic Scripting Edition (VBScript), most of you will elect to migrate to ASP .NET using Visual Basic .NET. This is obviously not a requirement, but changing languages at the same time you decide to migrate will take some additional effort and most likely will include design and architectural changes as well.

Coexistence

Before we get into discussing specific compatibility and migration issues, it is important that you understand how ASP and ASP .NET can coexist. Both ASP and ASP .NET applications can run side by side on a server without adversely affecting each other. This is primarily due to the fact that separate file extensions (.asp versus .aspx) and separate configuration models (metabase/registry versus XML-based configuration files) are used between the two technologies. The two systems have totally separate processing engines.
It is entirely possible to have part of one application running ASP and another part of the same application running ASP .NET. This is very beneficial if you need to move a large, rapidly changing site to ASP .NET one piece at a time. Some would argue that you may be better off porting and deploying the entire site all at once. This may be the case for certain classes of Web applications, but I think that there are a lot of sites out there where this may not be feasible due to the sheer size, complexity, and rapid evolution of the site's content and presentation. After all, if you are sitting on a profitable Web site, chances are the people paying the bills will not allow you to stop implementing their new features so that you can move things over to this hot new technology. Additionally, if you are going to put forth the effort to move to ASP .NET as a long-term investment, you will want to use this chance to make as many architectural and design improvements as you can. For these types of situations, coexistence using a phased-in approach is an absolute must.Compatibility Issues
Migrating your application to ASP .NET may not be easy; however, it should not be that difficult either. ASP .NET is very much compatible with ASP. This is impressive given the fact that ASP .NET is a complete overhaul of ASP. The designers of ASP .NET had an initial goal of being 100 percent backwards compatible with ASP but subsequently had to back off this goal in favor of improving the platform for the long haul. Not to worry—the changes made were for the better and should not require a lot of work on your part to implement. The actual changes made can be categorized into the following sections:

  • Core API changes
  • Structural changes
  • Visual Basic language changes
  • COM-related changes
  • Application configuration changes
  • State management issues
  • Security-related changes
  • Data access

Each of these areas will be discussed in detail.Core API Changes
The core APIs of ASP consist of a few intrinsic objects (Request, Response, Server, etc.) and their associated methods. With the exception of a few simple changes, these APIs continue to function correctly under ASP .NET. All of the changes are related to the Request object and are shown in Table 1:
Table 1. API ChangesMethodChangeRequest(item)In ASP, this method will return an array of strings. In ASP .NET, it returns a NameValueCollection.Request.QueryString(item)In ASP, this method will return an array of strings. In ASP .NET, it returns a NameValueCollection.Request.Form(item)In ASP, this method will return an array of strings. In ASP .NET, it returns a NameValueCollection.
As you can see, the changes are basically the same for all methods involved.
If the item you are accessing contains exactly one value for the specified key, you do not need to modify your code. However, if there are multiple values for a given key, you need to use a different method to return the collection of values. Also, note that collections in Visual Basic .NET are zero-based, whereas the collections in VBScript are one-based.
For example, in ASP the individual query string values from a request to http://localhost/myweb/valuetest.asp?values=10&values=20 would be accessed as follows:

<%   'This will output "10"   Response.Write Request.QueryString("values")(1)   'This will output "20"   Response.Write Request.QueryString("values")(2)%>

In ASP .NET, the QueryString property returns a NameValueCollection object from which you need to retrieve the Values collection before retrieving the actual item you want. Again, note the first item in the collection is retrieved by using an index of zero rather than one:

<%   'This will output "10"   Response.Write (Request.QueryString.GetValues("values")(0))   'This will output "20"   Response.Write (Request.QueryString.GetValues("values")(1))%>

In both the case of ASP and ASP .NET, the follow code will behave identically:

<%   'This will output "10", "20"   Response.Write (Request.QueryString("values"))%>

Structural Changes
Structural changes are those that affect the layout and coding style of Active Server Pages. You need to be aware of several of these to ensure your code will work in ASP .NET.

Code Blocks: Declaring Functions and Variables

In ASP, you can declare subroutines and global variables in between your code delimiters.

<%   Dim X   Dim str   Sub MySub()      Response.Write "This is a string."   End Sub  %>

In ASP .NET, this is no longer allowed. You must instead declare all of your functions and variables inside a <script> block.

<script language = "vb" runat = "server">   Dim str As String   Dim x, y As Integer   Function Add(I As Integer, J As Integer) As Integer      Return (I + J)   End Function</script>

Mixing Programming Languages

In ASP, you basically have two choices for your programming language: VBScript or Microsoft JScript. You are free to mix and match blocks of script in the same page at will.
In ASP .NET, you currently have three options. You can use C#, Visual Basic .NET, or JScript. Note that I said Visual Basic .NET instead of VBScript. This is because VBScript does not exist in the .NET platform. It has been fully subsumed by Visual Basic .NET. Although you are free to pick any of these languages, it is important to note that you cannot mix languages on the same page as you could do in ASP. It is certainly possible to have Page1.aspx of your application contain C# code while Page2.aspx of the same application contains Visual Basic .NET code. You just cannot mix them together in a single page.

New Page Directives

In ASP you must place all directives on the first line of a page within the same delimiting block. For example:

<%LANGUAGE="VBSCRIPT" CODEPAGE="932"%>

In ASP .NET, you are now required to place the Language directive with a Page directive, as follows:

<%@Page Language="VB" CodePage="932"%><%@QutputCache Duration="60" VaryByParam="none" %>

You can have as many lines of directives as you need. Directives may be located anywhere in your .apsx file but standard practice is to place them at the beginning of the file.
Several new directives have been added in ASP .NET. I encourage you to look these up in the ASP .NET documentation to see how they may benefit your application.

Render Functions Are No Longer Valid

In ASP, developers figured out that they could do clever things by using what is termed a "Render Function." A Render Function is basically a subroutine that contains chunks of HTML embedded throughout its body. For example:

<%Sub RenderMe()%><H3> This is HTML text being rendered. </H3><%End SubRenderMe%>

Although you can do some cool things using these types of functions, this type of coding is no longer allowed in ASP .NET. This is probably for the better. I am sure you have seen functions that quickly become unreadable and unmanageable when you start to mix and match code and HTML like this. The simplest way to make this work in ASP .NET is to replace your HTML outputs with calls to Response.Write as follows:

<script language="vb" runat="server">   Sub RenderMe()      Response.Write("<H3> This is HTML text being rendered. </H3>")   End Sub</script><%   Call RenderMe()%>

Note that I said "simplest way." This does not necessarily mean it is the best way. Depending on the complexity and amount of your rendering code, it may be beneficial for you to look into using custom Web controls, which allow you to programmatically set your HTML attributes and truly separate your code from your content. Doing so makes for much more readable code.Visual Basic Language Changes
As I mentioned earlier, VBScript has been deprecated in favor of the more complete and more powerful Visual Basic .NET. In this section, I will highlight some of the issues you are likely to encounter related to Visual Basic language changes. It is important to note that this is not meant to be an exhaustive list of all of the changes made to Visual Basic. Instead, I have focused on the items that you as an ASP/VBScript programmer will likely encounter moving to ASP .NET using Visual Basic .NET. Consult the Visual Basic .NET documentation for a complete list of all language changes that have been made.

Farewell to the Variant Data Type

We know it, we love it, we love to hate it. I am speaking of a VARIANT data type, of course. VARIANTs are not a part of .NET and thus are not supported in Visual Basic .NET. What this means is that all of your ASP variables are silently going to move from VARIANT types to Object types. Most variables used in your application can and should be changed to a corresponding primitive type depending on your needs. If your variable is really an object type in Visual Basic terms, simply explicitly declare it as an Object type in ASP .NET.

Visual Basic Date Type

One VARIANT type that warrants some special attention is the VT_DATE type, which manifests itself in Visual Basic as a Date type. In Visual Basic, a Date is stored in a Double format using four bytes. In Visual Basic .NET, Date uses the Common Language Runtime DateTime type, which has an eight byte integer representation.
Since everything is a VARIANT in ASP, your intended Date variables will compile and may continue to work depending on how they are used. It is possible, however, that you will run into some unexpected problems performing certain operations with the variable because the underlying type has been changed. Pay attention to areas where you may be passing the date value into COM objects as long integer values or performing certain casting operations on date types using CLng.

Option Explicit Is Now the Default

In ASP, the Option Explicit keywords were available but were not enforced as the default. In Visual Basic .NET, this has changed. Option Explicit is now the default so all variables need to be declared. It is good practice to be even more rigid than this and change your setting to Option Strict. Doing so forces you to declare all of your variables as a specific data type. While this may seem like extra work, it really is the way you should be doing things anyway. If you choose not to, your code will be less than optimal as all undeclared variables will become Object types. Most implicit conversions will still work, but you will probably be better off and safer if you explicitly declare all of your variables to the types you want them to be.

LET and SET Are No Longer Supported

Objects can be assigned to one another directly like this: MyObj1 = MyObj2. You no longer need to use the SET or LET statements. If you use these statements, they must be removed.

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索net
, asp
, to
, of
, The
You
,以便于您获取更多的相关知识。

时间: 2024-09-08 11:43:23

asp.net key considerations(一)从前用惯了asp的朋友看看这个吧,大家常问的如Request等问题解答得很清楚的相关文章

asp.net key considerations(三)

asp.net Authorization Once your users have been authenticated, you can focus on authorizing what resources you would like them to have access to. The following sample shows access being granted to "jkieley" and "jstegman," while everyo

asp.net key considerations(二)

asp.net Using Parentheses with Method Calls In ASP, you could freely call methods on objects without using parentheses, as shown below: Sub WriteData()   Response.Write "This is data"End SubWriteData In ASP .NET, you must use parentheses with al

《圣殿祭司的ASP.NET4.0专家技术手册》----1-1 ASP.NET平台的三分天下

1-1 ASP.NET平台的三分天下 圣殿祭司的ASP.NET4.0专家技术手册 如果访问微软www.asp.net网站,会发现ASP.NET技术目前有3位成员:Web Form.MVC和Web Pages,如图1-1所示.它们各有不同的定位与特色,彼此的开发方式也不相同.目前,使用人数与市场占有率最高的仍是Web Form,而MVC近两年有不少技术玩家和项目采用,至于Web Pages,则是另外的Web Matrix开发工具预定的网页开发技术,它走更易于使用的开发路线. 你心里可能有疑问:"为

ASP教程:第十六篇 其它的ASP常用组件

当你用 ASP 编写服务器端应用程序时,必须依靠 ActiveX 组件来强大 Web 应用程序的功能,譬如:你需要连接数据库,对数据库进行在线操作等等. 上两篇中作者给大家介绍了 AD Rotator. Database Access 等组件的使用方法,今天我们接着来看看其它的一些 ASP 常用组件. 一. Browser Capabilities 组件众所周知,并不是所有浏览器都支持现今 Internet 技术的方方面面.有一些特性,某些浏览器支持而另一些浏览器却不支持,如 : ActiveX

asp.net 2.0揭秘读书笔记一:ASP.NET和.NET Framework

<ASP.NET 2.0 揭秘>两卷书已经入手好些日子,却一直没有时间来细读,只偶尔需要的时候翻阅参 考,最近决定抽空通读,我把我认为有需要的地方作了笔记,录入博客,以备复习. ASP.NET是.NET Framework的一部分. 构建ASP.NET的页面,需要利用.NET FRAMEWORK的特性. NET Framework由两部分组成:框架类库(Framework Class Library)和公共语言运行时 框架类库 .NET Framework 2.0 包含了18 619种类型,1

解读ASP.NET 5 &amp; MVC6系列(1):ASP.NET 5简介

原文:解读ASP.NET 5 & MVC6系列(1):ASP.NET 5简介 ASP.NET 5简介 ASP.NET 5是一个跨时代的改写,所有的功能和模块都进行了独立拆分,做到了彻底解耦.为了这些改写,微软也是蛮 拼的,几乎把.NET Framwrok全部改写了一遍,形成了一个.NET Core的东西. 在.NET Core里一切都是可配置的,包括Session.MVC等功能,而一切可配置的功能都是可以在Nuget上进行下载. 目前ASP.NET 5依旧兼容老的.NET Framwrok,但要

ASP.NET学习篇(3)——几个简单的ASP.ENT的例子

一个WEBFORM--这里将介绍ASP.NET WEBFORM的基本概念,以及其中表单项的变化. *一个数据库的应用--如何利用CONFIG.WEB中设置的DNS连接数据库,数据库操作对象的一些基本用法. *EMAIL发送--在 引入一个系统类库后(用IMPORT 标识符 ),利用msgMail对象,可以很方便的操作邮件发送过程. *上传--<INPUT TYPE=FILE -- 这样一个INPUT 项在ASP.NET中有POSTEDFILE属性,结合SAVEAS 事件,就可以实现上传了. 一.

ASP编程入门进阶(十九):ASP技巧累加(二)

编程|技巧|技巧 严格控制Session 可以将不需要Session的内容(比如帮助画面,访问者区域,等等)移动到关闭Session的独立ASP应用程序中.在基础页面上,可以给ASP一个指示,让它不需要使用Session.将下面的代码直接加入到ASP页面的头部: <%@EnableSessionState=False%> 在Web服务器上缓存经常使用的数据 典型的情况是:ASP页面从后台存储中取回数据,然后以超文本标记语言(HTML)的形式形成结果.不管数据库的速度如何,从内存中取回数据要比从

在ASP中使用Java类(Using Java Classes from ASP)

Using Java Classes from ASP COM components aren't the only way to use compiled code in your ASP applications. If you're familiar with Java, but have no way of wrapping your classes as COM objects (for example, you use JDK or J++ Standard), you can st