asp.net key Considerations (ii)

Source: Internet
Author: User
Tags config configuration settings continue error handling exception handling iis iis administration visual studio
asp.net

Using parentheses with Method Calls


In ASP, your could freely call methods on objects without using parentheses, as shown below:
Sub writedata () Response.Write ' This Is data ' end Subwritedata

In ASP. NET, your must use parentheses with the your calls, even for methods, does not take any parameters. Writing your code, as in the example below, allows it to function correctly in both ASP and ASP.
Sub WriteData () Response.Write (' This is Data ') End Subcall WriteData ()

ByVal is now the Default


In Visual Basic, all parameter arguments were, by default, passed by reference or ByRef. In Visual Basic. NET, this has changed the all arguments are now passed by value or ByValBy default. If you are still wish to have " ByRef"Behavior, you must explicitly to use the ByRefkeyword in front of your parameters as follows:
Sub mybyrefsub (ByRef value) value = 53; End Sub

This is the where you really need to be careful. When your are moving your code over to ASP. NET, I suggest double and triple checking each parameter used in your method CA LLS to ensure which is what for you really want. I suspect you need to change some of them.

No more Default Properties


The concept of default properties no longer exists in Visual Basic. NET. What This means are that if you have ASP code that relies on a default to that's provided by one of your objects, Y Ou'll need to the explicitly reference the desired property, as shown in the following code:
' ASP Syntax (implicit retrieval of Column Value) Set Conn = Server.CreateObject ("ADODB. Connection ") Conn.Open (" TestDB ") Set RS = Conn.execute (" SELECT * FROM Products ") Response.Write RS (" Name ") ' asp.net Syntax (Explicit retrieval of Column Value) Conn = Server.CreateObject ("ADODB"). Connection ") Conn.Open (" TestDB ") rs = Conn.execute (" SELECT * FROM Products ") Response.Write (RS (" Name "). Value)

Changes in Data Types


In Visual Basic. NET, the Integer values are now bits and Long types have become.
Problems may arise the when invoking methods on COM objects from ASP. NET or calling Microsoft®win32®api calls inside your C ustom Visual Basic components. Pay special attention to the actual data types required to ensure your are passing in or casting values your.

Structured Exception Handling


Although the familiar On Error Resume Nextand On Error GotoError handling techniques are still allowed in Visual Basic. NET, they are not the best way to do things anymore. Visual Basic now has full-blown structured exception handing using the Try, Catch, and FinallyKeywords. If possible, you are should to the new model for the error handling as it allows for a more powerful and consistent Mechanis M in dealing with your application errors. com-related Changes
With the introduction of the. NET Framework and ASP. NET, COM really has not been changed in all. This is does not mean, however, which you don't need to worry about COM objects and how they behave if you are using them f Rom ASP. NET. There are a couple of fundamental things you need to be aware of.

Threading Model Changes


The ASP. NET threading Model is the multiple threaded Apartment (MTA). What This means are that components so you are using then were created for the single threaded (STA) would no lo Nger perform or function reliably without taking some extra precautions in ASP. NET. This includes, but isn't limited to, all COM components that have been using Visual Basic created and 6.0 version S.

ASPCompat Attribute


You'll be glad to hear, can still use this, these STA components without have to change any code. What you need to does is include the compatibility attribute aspcompat=trueIn a <% @Page > tag on the ASP. NET Page. For example, <% @Page aspcompat=true language=vb%>. Using This attribute would force your page to execute in STA mode, thus ensuring your component would continue to function C orrectly. If you are attempt to use a STA component without specifying this tag, the run time would throw an exception.
Setting This attribute to true would also allow your page to call COM + 1.0 components that require access to the unmanaged ASP built-in objects. These are accessible via the ObjectContextObject.
If you are set this tag to true, your performance'll degrade slightly. I suggest doing this is only if your absolutely need to.

Early Binding versus Late Binding


In ASP, all calls to COM objects occur through the IDispatchInterface. This is known as "late binding" because calls to the actual objects are handled indirectly via IDispatch At run time. In ASP. NET, you can continue to invoke your components into this fashion if you like.
Dim Obj as Objectobj = Server.CreateObject ("ProgID") Obj.mymethodcall

This works but it isn't the preferred manner to access your components. With ASP. NET, can now take advantage of early binding and create your objects directly as follows:
Dim OBJ as New Myobjectmyobject.mymethodcall ()

Early binding allows to interact with your components in a type-safe manner. In order to take advantage of the early binding with your COM components, where you need to add a reference in your project The same way that you add a COM reference to a Visual Basic 6.0 project. Assuming that you are using Visual Studio. NET, a managed proxy object are created behind the scenes, on top of your COM co Mponent, giving you the impression for you are dealing directly with your COM component as a. NET component.
At I/May wonder about performance. There is definitely some overhead involved when using COM interoperability as (you) have an extra layer introduced BECAU SE of the proxy object. In most cases, however, this is not being be a factor because the amount of actual of CPU instructions for the interoperation to occur is still substantially less than this required by your indirect IDispatchCalls. You are gaining more than your would lose. The ideal situation, of course, is-to-use newly created, managed objects, but we know. E immediately because of our investments in COM components over the years.

OnStartPage and OnEndPage Methods


One area which needs some additional consideration involves the use of the legacy OnStartPageand OnEndPageMethods. If you are rely on this methods to access ASP intrinsic objects, you'll need to use the ASPCompatDirective and use Server.CreateObjectTo create your component in a early-bound fashion, as shown below:
Dim Obj as Myobjobj = Server.CreateObject (myobj) Obj.mymethodcall ()

Notice that instead of using the ProgID,"We have used the actual type in a early-bound manner. In the order is to work and you'll need to add a reference to your COM component in your Visual Studio project so th E Early-bound wrapper class is created for you. This is the only case where your must continue to use should Server.CreateObject.

COM Summary


Table 2 is a summary of what for your need to did to continue to use your COM components as efficiently as.
Table 2. ASP. NET Settings for Legacy COM Objects
COM Component type/methodasp. NET setting/procedures Custom STA(Visual Basic components or other components marked as "Apartment") Use ASPCompat, use early binding Custom MTA(ATL or custom COM components marked as "Both" or "free") Don't use ASPCompat, use early binding intrinsic Objects(Accessed via ObjectContext) use ASPCompat, use early binding OnStartPage, OnEndPageUse ASPCompat, use Server.CreateObject (Type)
These same settings apply whether or not your components are deployed in COM +. Application Configuration Changes
In ASP, all WEB application configuration information are stored in the system registry and the IIS Metabase. This is makes it quite difficult to view or modify settings because often the correct administration tools are not even Insta lled on your server. ASP. NET introduces a whole new configuration model based on simple, human readable XML files. Each ASP. NET application has its own Web.configfile that lives in its main application directory. It is here This control the custom configuration, behavior, and the your WEB application.
If you are are like I am, you'll be tempted to the "Internet Services Manager snap-in to inspect and change the Settin GS for your ASP. NET application. Understand, however, that we now have two totally separate configuration. With the exception of some security settings, for the most part all settings made using the IIS administration tool are ignored by ASP. NET applications. You are need to place your configuration settings in the Web.configFile.
application configuration with. NET is a article in itself and I won't detail it here. Table 3 shows some of the more interesting configuration sections your can set in your file. Keep in mind that there are many more.
Table 3. Sample Web.config Settings
Settingdescription
<appSettings>
Configures custom application settings.
<authentication>
Configures ASP. NET authentication support.
<pages>
Identifies page-specific configuration settings.
<processModel>
Configures the ASP. NET process Model settings on IIS systems.
<sessionState>
Specifies session state options.
There are classes available in the. NET Base Class Libraries This simplify programmatic access to these settings. State Management
If your application uses the SessionOr ApplicationIntrinsic object to store state information, you can continue to use this in ASP. NET without any problems. As a added benefit, you are now have a couple the more options for your state storage location.

State Management Options


In ASP. NET, your have additional options for your state storage model that'll finally allow you to go beyond a single We b Server and support state management across a Web farm.
You are configure your state management options in the <sessionState> section of your Web.config file as follows:
<sessionstate mode= "Inproc" stateconnectionstring= tcpip=127.0.0.1:42424 "sqlconnectionstring=" Data source=127 .0.0.1;user id=sa;password= "cookieless= false" timeout= "/>"

The "mode" specifies where you would like to store your state information. Your options are Inproc, StateServer, SQL Server, or off.
Table 4. Session state Storage Information
Optiondescription InprocSession ' is stored locally to this server (ASP style). StateServerSession ' stored in a ' state service process located remotely or potentially locally. SQL ServerSession's stored in a SQL Server database. offSession ' is disabled.
stateconnectionstringand sqlConnectionStringObviously come into factor if your use one of the other options. You can only use one storage option per application.

Storing COM components


One thing to keep into mind is this if you rely on storing references to your legacy COM components in the SessionOr Applicationobject, you cannot use the new state storage mechanisms ( StateServerOr SQL Server) within your application. You'll need to use Inproc. This is due, in part, for the need of "an", "self-serializable in. NET terms, something that COM components Obvio usly cannot do. New, managed components you create, on the other hand, can does this relatively easily and thus can is the new state Storag E models.

Performance


As far as performance goes, nothing comes to free, of course. One can safely assume that in most cases, InprocWould continue to being the best performer, followed by StateServerand then SQL Server. You should perform your own tests with your application to ensure the option select would meet your the performance goals.

Sharing state Between ASP and ASP. NET


Another important thing to consider are that although your application can contain both ASP and ASP. NET pages, for you cannot Share state variables stored in the intrinsic SessionOr ApplicationObjects. You are either need to duplicate this information in both systems or come up with a custom solution until your application are Fully migrated. The bottom line is this if have made little use of the Sessionand Applicationobjects, you should is in good shape. If, on the other hand, your use this objects extensively, you'll need to proceed with caution and perhaps Custom short-term solution to sharing your state. security-related Changes
Security are another area This requires a great deal of focus. This is a brief overview of the ASP. NET security System. Consult the ASP. NET Security documentation for a more thorough investigation.
ASP. NET security are primarily driven from settings in the security sections of your Web.config file. ASP. NET works in concert with the IIS to provide a complete security model for your application. IIS security settings are some of the few application settings that would actually carry over and is applied to your ASP. N ET application in a similar manner into that in ASP. There are, of course, many additional enhancements.

Authentication


For authentication, ASP. NET supports the different options shown in Table 5.
Table 5. ASP. NET Authentication Options
Typedescription WindowsASP. NET uses Windows authentication. Formscookie-based, custom login forms. PassportExternal Microsoft provided Passport Service. NoneNo authentication is performed.
These are the same options for your have in ASP, with the exception of the new PassportAuthentication option. As a example, the following configuration section enables windows-based authentication for a application:
<configuration> <system.web> <authentication mode= "Windows"/> </system.web></configura Tion>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.