By simply configuring IIS and using urlwriter, URL rewriting can be perfectly solved.
You can change http://abc.domain.com/blog
Turn to http://www.domain.com/xxx.aspx? Username = ABC
Of course, you must first enable the wildcard domain name support of the host.
The procedure is as follows:
A. Open IIS, right-click the site (virtual directory)-> properties-> main directory-> Configuration-> insert-> C: \ WINDOWS \ Microsoft. net \ framework \ v2.0.50727 \ aspnet_isapi.dll. If the file exists, click OK.
B. Modify webconfig:
<Rewriterconfig>
<Rules>
<Rewriterrule>
<Lookfor> http: // localhost/(blog) </lookfor>
<Sendto> ~ /Sdfsdf. asxp? Tag = $1 </sendto>
</Rewriterrule>
</Rules>
</Rewriterconfig>
C. Modify urlrewriter
Download source code from Microsoft,
1. basemodulerewriter. CS
Protected virtual void basemodulerewriter_authorizerequest (Object sender, eventargs E)
{
Httpapplication APP = (httpapplication) sender;
Rewrite (App. Request. Path, APP );
}
Change
Protected virtual void basemodulerewriter_authorizerequest (Object sender, eventargs E)
{
Httpapplication APP = (httpapplication) sender;
Rewrite (App. Request. url. absoluteuri, APP );
}
Replace app. Request. path with app. Request. url. absoluteuri.
2. modulerewriter. CS
For (INT I = 0; I <rules. Count; I ++)
{
// Get the pattern to look for, and resolve the URL (convert ~ Into the appropriate directory)
String lookfor = "^" + rewriterutils. resolveurl (App. Context. Request. applicationpath, rules [I]. lookfor) + "$ ";
// Create a RegEx (note that ignorecase is set)
RegEx Re = new RegEx (lookfor, regexoptions. ignorecase );
// See if a match is found
If (Re. ismatch (requestedpath ))
{
// Match found-Do any replacement needed
String sendtourl = rewriterutils. resolveurl (App. Context. Request. applicationpath, re. Replace (requestedpath, rules [I]. sendto ));
// Log rewriting information to the trace object
App. Context. Trace. Write ("modulerewriter", "Rewriting URL to" + sendtourl );
// Rewrite the URL
Rewriterutils. rewriteurl (App. Context, sendtourl );
Break; // exit the For Loop
}
}
Change
For (INT I = 0; I <rules. Count; I ++)
{
// Get the pattern to look for, and resolve the URL (convert ~ Into the appropriate directory)
String lookfor = "^" + rules [I]. lookfor + "$ ";
// Create a RegEx (note that ignorecase is set)
RegEx Re = new RegEx (lookfor, regexoptions. ignorecase );
// See if a match is found
If (Re. ismatch (requestedpath ))
{
// Match found-Do any replacement needed
String sendtourl = rewriterutils. resolveurl (App. Context. Request. applicationpath, re. Replace (requestedpath, rules [I]. sendto ));
// Log rewriting information to the trace object
App. Context. Trace. Write ("modulerewriter", "Rewriting URL to" + sendtourl );
// Rewrite the URL
Rewriterutils. rewriteurl (App. Context, sendtourl );
Break; // exit the For Loop
}
}
Set
String lookfor = "^" + rewriterutils. resolveurl (App. Context. Request. applicationpath, rules [I]. lookfor) + "$ ";
Changed
String lookfor = "^" + rules [I]. lookfor + "$ ";
OK.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zj1103/archive/2009/04/18/4089664.aspx