asp.net key Considerations (iii)

Source: Internet
Author: User
Tags continue functions new features prepare requires types of functions
asp.net

Authorization


Once your users have been authenticated, can focus on authorizing what and would like them to have access to . The following sample shows access being granted to "Jkieley" and "Jstegman," while everyone else is denied access.
<authorization> <allow users= "Northamerica\jkieley, Redmond\jstegman"/> <deny "*" users= Authorization>

Impersonation


As a refresher, impersonation refers to the process whereby an object executes code under the identity of the entity on WH OSE behalf it is performing. In ASP, impersonation'll allow your code to run on the behalf of authenticated user. Alternately, your users can run anonymously under a special identity. By default, ASP. NET does does per-request impersonation. This is different from ASP. If you are rely on this capability, you'll need to the enable this in your Web.config file as follows:
<identity> <impersonation enable = "true"/></identity>
Data Access
Another key area you could need to the for your migration efforts is this of data access. With the introduction of ADO. NET, you are have a powerful new way to get at your data. Since data access is a large topic in itself, it goes beyond the scope of this article. For the most part, you can continue to use ADO as your have in the past, but I highly recommend taking a look at ADO. NET A s a means to improve your data access methods within ASP. NET your. preparation for ASP. NET
Now this you have been exposed to most of the issues your are likely to encounter, your may is wondering what you can Do this is better prepared for them, you are finally move to ASP. Quite a few things can be done by that'll make the process smoother. Many of these suggestions'll be is beneficial to your ASP code even if you don't move to ASP. NET until sometime in the FU Ture.

Use Option Explicit


This is has always been a good idea but still not everyone uses it. By enforcing variables to is declared in ASP by using Option Explicit, you'll at least have a handle the where everything is defined and I your variables are being. Once to ASP. NET, I suggest using Option Strict. Option ExplicitWould be is the default in Visual Basic. NET but by using the more enforcing Option Strict, you'll ensure all of your variables are declared as the correct data type. Doing this definitely requires a bit of extra work but, in the long run and you'll discover it.

Avoid Using Default Properties


As we discussed, default properties are no longer allowed. Accessing your properties explicitly isn ' t really that hard to do anyway. It'll make your code more readable and also save with the future in porting.

Use parentheses and the call Keyword


Use parentheses and CallStatements wherever possible, as detailed earlier in this article. In ASP. NET you are forced to use parentheses. Using the CallStatement today would help you to add a bit of discipline that'll better prepare for the future.

Avoid Nested Include Files


This is easier said than done but, if possible, for you should avoid nesting your include files. To clarify what I mean by this, and you should try-to-eliminate any areas where and have include files that include the other incl Ude files. What tends to happen over the time was that your code ends up relying on a global variable this is defined in a include file s Omewhere else, and you are getting access to it only because your have included another file that includes the one your real ly need.
When you are migrate to ASP. NET, you'll most likely is moving your global variables and routines into class libraries, in W Hich case, it's much easier to does if you are have a clear picture of where your are getting access to everything. You could end up has a to move things around and change some routines ' names that were duplicated in multiple files.

Organize Utility functions to single Files


One strategy used in the migration process are to migrate all of the utility functions and code contained in your De include files into Visual Basic or C # class libraries. This allows to finally put all of the code where it belongs-in objects, as opposed to multiple-interpreted ASP files. By organizing your code ahead of time, you'll be saving yourself time in the future. Ideally, you should is able to group your sub-routines together in logical files thus allowing your to easily create a set of VB or C # classes. These are the "functions" probably should have been in COM objects in the.
If you have a bunch of the global variables or constants mixed in server-side include files, consider placing all of them in a Single file, as. Once to ASP.. NET, can then easily create a class that would house your global or constant data. This is a much cleaner and more maintainable system.

Remove Code from Content as much as Possible


This is another thing it easier said than do but, if at all possible, for you should separate the code from HTML your NT. Clean up functions which mix code and script throughout a function body. Doing so puts for a much better position to leverage Code-behind as the the ideal model under ASP. NET anyway.

Do not Declare functions Inside <%%> Blocks


This isn't supported in ASP. NET. You are should be declaring your functions inside <script> blocks. The structural Changes section earlier into this article for a example of this technique.

Avoid Render functions


As discussed earlier, you should avoid using "render functions." If you can change or prepare your The code now, your should be using Response.WriteBlocks when constructing these types of functions.

Explicitly free resources (call Close Methods)


Make sure your explicitly call any Close ()Or cleanup methods that exist in the objects and resources are using. We know how forgiving Visual Basic and VBScript are when it comes to cleanup. Normally, they are pretty good at cleaning things up immediately but, as we are to. NET and the garbage-collected world, One cannot is sure exactly when objects'll be cleaned up. If You can cleanup and release your resource explicitly, you should.

Avoid mixing Languages


If possible, you are should avoid intermixing server-side VBScript and JScript in the same page. In general, this is a poor programming practice anyway. This is also a migration issue for ASP. NET in, it requires only one inline <%%> language per page because of T He new compilation model. Can continue to emit client-side script in the same manner as, are used to. Summary
As you have seen, there are a quite a few things your need to is aware of before moving-your-application to ASP. NET but MO St of the changes I have outlined should is relatively easy for your to implement.
If you are have a large site, you are amazed when you are finished with this process at the amount of dead code, Inefficie Ncies, and outright bugs you came across and fixed. Additionally, you are able to take advantage of the many powerful new features to ASP. NET added In general.

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.