Solving the problem of HTTP handler in IIS6 and IIS7

Source: Internet
Author: User
Tags memory usage


This article and you share the HTTP handler from IIS6 to IIS7 use of the problem, I hope to help you. Recently wrote a monitoring server status of the page, the content is very simple, is to show the server's current CPU and memory usage. Because want it to refresh every 3 seconds, so put the function on the ASHX page, the page every 3 seconds call.

$ (document). Ready (function () {
LoadData ();
SetInterval (LoadData, 3000);
});
function LoadData () {
$.getjson ("common/serverinfohandler.ashx?format=json&jsoncallback=?", {}, Function (JSON) {
$ ("#labServerName"). Text ("Server name:" + JSON.) ServerName);
$ ("#labServerIP"). Text ("Server address:" + JSON.) ServerIP);
$ ("#NumberOfProcessors"). Text ("CPU number:" + JSON.) Cpunum);
$ ("#ProcessorType"). Text ("CPU type:" + JSON.) Cputype);
$ ("#ProcessorLevel"). Text ("CPU level:" + JSON.) Cpulevel);
$ ("#MemoryLoad"). Text ("Memory usage:" + JSON.) Memoryload);
$ ("#TotalPhys"). Text ("Physical memory is common:" + JSON.) Memorytotalphys);
$ ("#AvailPhys"). Text ("Available physical memory is:" +
$ ("#Date"). Text ("Server time:" + JSON.) DateTime);
$ ("#cpu"). Text ("CPU average usage:" + JSON.) Cpuload);
});
}

Things are very simple, after writing with Visual Studio directly run, found that the server name and address is 127.0.0.1, so I would like to deploy on IIS to see. The development of the machine is Win7, with the IIS7, this thing is really useless, and IIS6 difference is too big, for a while indeed a bit can not find north. After a very easy deployment, the browsing page found no information displayed, debugging in Visual Studio, found that the ASHX page was not invoked at all.

But put "dog", may be I was "dog" in the direction of the wrong bar. "Dog" out of a pile of information, found not to work, can not solve the problem. Published to the test server, Windows Server 2003 +IIS6, this deployment will not be a problem to browse. At that time I was very depressed ah. The most feared is this kind of unthinking problem.

I said to my colleague, he was idle, no meet sent me a page, the birds of the

Http://forums.asp.net/t/1421108.aspx

See the above basically that is to add configuration, try, no one works, but this page is the beginning of the problem, although the reply to the inside does not have a way but the second reply (the legendary sofa), provided a link, said is a solution. Let's go over there.

Http://www.infosysblogs.com/microsoft/2007/02/configuring_custom_http_handle.html

I don't have the patience to look at each word, see a few points, is in the IIS7 of your site

Inside the upper right corner

Add managed handlers plus your ashx.

I am not patient, see this I directly in IIS added, found that still not. Looking back at someone else's writing, he said that the type has automatically identified his ashx, I was directly handwritten, which is very problematic ah, but my type does not recognize it. and see the following configuration code

< system.webserver >
< handlers >
< AddName = "Custom Handler" path = "*.sample" verb = "*" type = "HelloWorldHandler"
ResourceType = "Unspecified"/>
</system.webserver >

Cuff to say, throw in my Web.config change bar, or not. Careless bad things, and found that people also gave an MSDN how Toarticle link, point in to see. That's clear.

There are birds of the bird good, down can not see I wrote the directly to see MSDN on the good. The birds are bad. I'll explain briefly.

You have to use synchronous httphandlers not to build ashx, but to build a class in the App_Code, then inherit, implement IHttpHandler code

Usingsystem.web;

public class Helloworldhandler:ihttphandler
{
Public HelloWorldHandler ()
{
}
Public Voidprocessrequest (HttpContext context)
{
Httprequestrequest = context. Request;
HttpResponse Response = context. Response;
This handler is called whenever a file ending
In. sample is requested. A file with that extension
Does not need to exist.
Response.Write ("Hello Handler.") " );
}
Public boolisreusable
{
To enable pooling, return true here.
This is keeps the handler in memory.
get {return false;}
}
}

Then, configure Web.config. There are three ways to configure this problem.

IIS6:

< configuration >
< system.web >
< httphandlers >
< add verb = "*" Path = "*.sample"
Type = "HelloWorldHandler"/>
</system.web >
</configuration > IIS7 is the Classic mode and integrated mode of two working modes, so the configuration is divided into two kinds.
Classic mode is for compatibility with previous versions, using ISAPI extensions to invoke the ASP.net runtime, and migrating Web applications running under IIS6.0 to IIS7.0 as long as the application is configured in Classic mode, the code can run normally without modification.
Configured as follows
Code
<configuration>  <system.web>    Configuration
Code
<configuration> <system.webServer> <add verb= "*" path= "helloworld.sample" name= "HelloWorldHandler" type= "HelloWorldHandler"/><add verb= "*" Path= "Helloheaven.sample" name= "Helloheavenhandler" type= "Helloheavenhandler"/>
After the configuration can be tested on their own handler, the test address is as follows http://localhost/HttpHandler/test.sample of course, if you set the name can be used

Http://localhost/HttpHandler/HelloWorld.sample Http://localhost/HttpHandler/HelloHeaven.sample
When it's used, it becomes.
$.getjson ("handlerhelloworld.sample?format=json&jsoncallback=?",...... There is actually a problem here, I hope to have a brother know the words to the younger brother FAQ.
Write handler words with the class ashx. How to use AH.
The generic handler (ASHX) is optional when you add a new file.
There is IIS6 and IIS7 to write different three kinds of configuration, there is no general writing. Do not specify some kind of IIS without specifying it.

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.