Ii. rewritepath method of ihttpmoduleHow can I come by myself? Can I write an isapi in c ++? A: No. I wrote it honestly with. net. That's easy: from global. asax moved to ihttphandle for a long time. After a wrong direction, it was still in the same place. Then it was discovered after a local search. The path had to go to ihttpmodule. It is easy to use ihttpmodule. Many people use this as a result. Write a class that inherits from ihttpmodule and register it in the configuration file. The example is as follows:1: Create a class library project: Name: urlrewrite2: Add reference system. web, because the ihttpmodule is in this namespace, and the class library does not reference this by default.3: Rename class1.cs to urlrewrite. cs, and let the class inherit from ihttpmodule to implement the interface as follows:Adjust the Code as follows: # region ihttpmodule member public void dispose ()
{
// Throw new exception ("the method or operation is not implemented .");
} Public void init (httpapplication context)
{
Context. beginrequest + = new eventhandler (context_beginrequest );
} Void context_beginrequest (object sender, eventargs e)
{
Httpapplication app = (httpapplication) sender;
Httpurlrewrite (app. context );
}
Public void httpurlrewrite (httpcontext context)
{
String url = context. request. url. tostring (); // The url requested by the user
// -- Perform a lot of url logic processing here
Context. rewritepath ("~ /Default. asp tutorial x ", null," url = "+ url );}
# The code above endregion indicates that the whole request url is sent to the default. aspx page as a parameter, and all requests are converted to default. aspx? Url = www.cyqdata.com in a similar wayNext, create another site to accept and output the result:4. Add the new website name urlrewritedemo.Pstutorial: the app was originally to be created. If you cannot open the example when downloading it, the sample is in the form of a website.5. add reference to the urlrewrite Project6: f5, call up web. config, and add the configuration item code in the configuration file as follows: <Httpmodules>
<Add name = "urlrewrite" type = "urlrewrite. urlrewrite, urlrewrite"/>
</Httpmodules> for the current situation example, write a line of code to default. aspx and output the received parameter protected void page_load (object sender, eventargs e)
{
Response. write (request ["url"]);
}Everything is ready and running. Let's look at the results:Figure 1: The default page of the request. The output result indicates that the page is normal.Figure 2: If you request a page that does not exist, the output result is normal.Figure 3: request a url without a suffix and output the result, which is a bit surprisingAs shown in figure 3, it seems that iis integrated with vs2005 processes all requests in a unified manner, so it can be processed even without a suffix.Important Notes:For iis Site Development or final deployment, the default aspnet_isapi.dll cannot handle suffixes without suffixes or images. Therefore, you need to add extended generic mappings to achieve this function.