Artificial traps in ASP. NET are not Microsoft problems, but some pitfalls in ASP. NET.

Source: Internet
Author: User
Tags apm

Let's just talk about two things. This article appears on the homepage.

Extract a microblog and try to avoid the problem of incorrect direction in technical understanding: it is not a Microsoft problem, it is your understanding problem.

 

"Clear thinking is far more important than hard work. the right direction is more important than diligence, and doing the right thing is more important than doing the right thing.

People and things are often evaluated to evaluate the superficial phenomena, ignoring the connotation.

In the end, some truly valuable people and things were left out of the cold, and the others were touted !"

 

 

I. I didn't understand what multithreading is, so the following conclusions are all wrong.

*****************************

Access HttpContext. Current in the following scenarios will return null
1. Timer callback.
2. Cache removal notification.
3. Callback is completed asynchronously in APM mode.
4. Actively create a thread or submit the task to the thread pool for execution.

*************************************

In the following cases, HttpContext. Current is null, not a pitfall.

Ii. Basic concepts have not been clarified

 

*****************************
QueryString and Form allow duplicate keys ????

Isn't that true?

The dictionary class allows duplicate keys. Can the parameter names in the request string be keys?

*************************************

Correct Response: The same parameter names are allowed in the request string. The value of the same parameter names is separated by "," In QueryString.
QueryString does not have duplicate keys. Do not mislead everyone.

Original article: http://www.cnblogs.com/fish-li/archive/2013/05/28/3104750.html

Partial excerpt:

 

Some pitfalls of ASP. NET

Reading directory

  • Start
  • HttpContext. Current is not everywhere
  • Application_Start exception and IIS Classic Mode
  • QueryString and Form allow duplicate keys
  • Ashx Reuse
  • Currently logged on user information is sometimes not available
  • Timer may not work
  • Session and complex data types
  • JSON serialization of DateTime
  • Recruitment Information

Some time ago I encountered a problem: Why does the timer sometimes not work in ASP. NET programs?

This problem looks strange, and the code seems to be correct, but the results are inconsistent with expectations.
In fact, this is a trap of ASP. NET programs. Later, I thought about ASP. NET. I wrote all the pitfalls I can think of today. I hope you will be careful with these problems.

I have mentioned some pitfalls in my previous blog, so I listed them in this blog. However, I will only briefly describe the content I have talked about before.

Returning to the top of HttpContext. Current is not everywhere

This problem is the one I mentioned in my blog last month.

Access HttpContext. Current in the following scenarios will return null
1. Timer callback.
2. Cache removal notification.
3. Callback is completed asynchronously in APM mode.
4. Actively create a thread or submit the task to the thread pool for execution.

Therefore, pay attention to this issue when writing a class library.

Return to the top Application_Start exception and IIS Classic Mode

When you run an ASP. NET Program in IIS6 or II7 Classic mode, if an uncaptured exception is thrown in the Application_Start eventThis exception is displayed once.

For more details about this problem, click: http://www.cnblogs.com/fish-li/archive/2013/03/24/2979780.html

Return to QueryString at the top. The Form allows duplicate keys.

We often see collections, such as Hashtable and Dictionary, which require that keys be unique. However, the QueryString and Form set instances of HttpRequest areDuplicate keys allowedWhen duplicate keys are encountered and the set is accessed through the indexer,Concatenates all element values corresponding to the KEY with commas.

Why? Because the two sets are of NameValueCollection type, similar to Headers.

Because this particularity is different from our common situation, we need to pay attention to this difference. Of course, sometimes we can use this behavior to meet some special requirements, for more information about this details, see: http://www.cnblogs.com/fish-li/archive/2011/12/06/2278463.html, In this blog, also introduced the two indexers of HttpRequest is worth noting.

 

Reading directory

  • Start
  • HttpContext. Current is not everywhere
  • Application_Start exception and IIS Classic Mode
  • QueryString and Form allow duplicate keys
  • Ashx Reuse
  • Currently logged on user information is sometimes not available
  • Timer may not work
  • Session and complex data types
  • JSON serialization of DateTime
  • Recruitment Information

Some time ago I encountered a problem: Why does the timer sometimes not work in ASP. NET programs?

This problem looks strange, and the code seems to be correct, but the results are inconsistent with expectations.
In fact, this is a trap of ASP. NET programs. Later, I thought about ASP. NET. I wrote all the pitfalls I can think of today. I hope you will be careful with these problems.

I have mentioned some pitfalls in my previous blog, so I listed them in this blog. However, I will only briefly describe the content I have talked about before.

Returning to the top of HttpContext. Current is not everywhere

This problem is the one I mentioned in my blog last month.

Access HttpContext. Current in the following scenarios will return null
1. Timer callback.
2. Cache removal notification.
3. Callback is completed asynchronously in APM mode.
4. Actively create a thread or submit the task to the thread pool for execution.

Therefore, pay attention to this issue when writing a class library.

Return to the top Application_Start exception and IIS Classic Mode

When you run an ASP. NET Program in IIS6 or II7 Classic mode, if an uncaptured exception is thrown in the Application_Start eventThis exception is displayed once.

For more details about this problem, click: http://www.cnblogs.com/fish-li/archive/2013/03/24/2979780.html

Return to QueryString at the top. The Form allows duplicate keys.

We often see collections, such as Hashtable and Dictionary, which require that keys be unique. However, the QueryString and Form set instances of HttpRequest areDuplicate keys allowedWhen duplicate keys are encountered and the set is accessed through the indexer,Concatenates all element values corresponding to the KEY with commas.

Why? Because the two sets are of NameValueCollection type, similar to Headers.

Because this particularity is different from our common situation, we need to pay attention to this difference. Of course, sometimes we can use this behavior to meet some special requirements, for more information about this details, see: http://www.cnblogs.com/fish-li/archive/2011/12/06/2278463.html, In this blog, also introduced the two indexers of HttpRequest is worth noting.

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.