Why does my httpmodule seem to work?
After setting breakpoints in the httpmodule program, no matter what, the process does not go from here. The reason is that you did not register your httpmodule program with the web program. This work needs to be completed in.
<>
<httpModules>
<add type=", URLRewriter" name="ModuleRewriter" />
</httpModules>
</>
Why is it always prompted for "Unknown configuration section RewriterConfig error"
This is because you are not registering your RewriterConfig configuration section with the web program. This work needs to be done in.
<configSections>
<section name="RewriterConfig" type=", URLRewriter" />
</configSections>
Then, you can use the RewriterConfig section to configure the rules in <configuration>.
Which part of the url is processed in httpmodule?
Most of the work is in the URLRewriter. ModuleRewriter. Rewrite() method. The key stage is here:
if ((requestedPath))
It is obvious that this judging whether the url passed in is the url we want to rewritten. Let's continue to see,
String sendToUrl = (, (requestedPath, rules[i].SendTo));
Here you accept the target url to be transferred to in the configuration in the
(, sendToUrl);
Rewrite the url internally.
I don't want to write the second-level domain name to death, and the target url I want to rewritten cannot be written to death. For example, we have this need
The actual processing page is /?id=1
The actual processing page is /?id=2
The actual processing page is /
How to deal with it?
At this time, you need to do something in the code mentioned above.
if ((requestedPath))
{
//Find the secondary domain name in the url
string [] UserHost = ( new Char [] { '.' } );
string domain2=UserHost [0];
//Set the target url to be rewritten as needed
string sendToUrl ;
if(domain2==” Love”)
sendToUrl =” /?id=1”;
else if(domain2==” call”)
sendToUrl =” /?id=2”;
else i f(domain2==” walkwith”)
sendToUrl =” /”;
(, sendToUrl);
}
When configuring rules, this is needed
<RewriterRule>
<LookFor>http://(\w+)\.kerry\.com</LookFor>
<SendTo>/</SendTo>
</RewriterRule>
(\w+) is used to match any string
It is also OK to write anything else here because we didn't use it at all.
I have many sites that are not sure about the secondary domain name, but the page of each site is determined, and the content of each secondary domain name site is actually different from the database.
This is the case
http://localhost/kerry/?id=1 /
http://localhost/kerry/?id=14 /
Now that it is uploaded, the id parameter cannot be displayed, and it is changed to a second-level domain name. What should I do at this time?
First configure the rules
<RewriterRule>
<LookFor>http://(\w+)\.kerry \.com\ </LookFor>
<SendTo>/</SendTo>
</RewriterRule>
Then handle it in the program
//Get the secondary domain name
string [] UserHost = ( new Char [] { '.' } );
string domain2=UserHost [0];
Obtain different numbers according to the domain name
int id=getIDfromDomain(domain2);
//Get the basic url to turn
string sendToUrl = (, (requestedPath, rules[i].SendTo));
//Add id parameter
if(id>0)
sendToUrl= ( "{0}?id={1}" , sendToUrl , id );
else
sendToUrl=””;
//Rewrite
(, sendToUrl);
How to match the directory? I wrote a lookfor rule /, but when I entered this address in the browser, I could not rewrite it correctly. After passing the trace, I found that it could not match at all. Why?
First of all, we should know that the browser actually accepts not /, but / , so your</LookFor> rules should be written like this
<LookFor>
/
</LookFor>
This should be the default document you configured in IIS. If your name is or other strange names, write it as your own name
Similarly, if the address /fun is matched, such a rule is required /fun/
But, to be more verbose, your file doesn't need to have the fun directory, because... it's rewritten.
I found another solution online...
Maybe you mean this article
/mengyao/archive/2007/01/25/
You can see that the basic methods are the same. The reason why this is not listed first is because this method is a bit tricky, which may not be so easy to understand at the beginning. But I believe that when you see the last friend who reads this article, you will smile knowingly.
Happy programming