There may be no one to use the method in the previous article for URL rewrite because the components that provide URL rewrite are already overwhelming.
Asp. Net-level URL rewrite component is simple enough to listen to the BeginRequest event and determine the target URL based on the configuration. In the project I contacted earlier, I found that using urlrewriter as a URL rewrite component is very high, I think it is because that is what Microsoft provides.
If you want to use Urlrewriter, you first naturally configure a HttpModule in web.config:
Then it is configured (note: It is highly recommended that you use the Configpath property to extract the configuration into additional files for easy management):
<configSections>
<section name= "rewriterconfig"
type= " URLRewriter.Config.RewriterConfigSerializerSectionHandler, Urlrewriter "/>
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<lookfor>~/tag/([\w]+)/</ Lookfor>
<sendto>~/tags.aspx? tag=$1</sendto>
</RewriterRule>
</Rules>
</RewriterConfig>
A regular expression is a very important thing that can be matched and captured. In the above example, we put the "/tag/xxx" that meets the lookfor condition Reposition to the tags.aspx page and use XXX as the value of the QueryString item, so that the value can be obtained by httpcontext.request.querystring["tag" in the code.
Urlrewriter's function is sufficient for most applications, but I always dislike it. But if I have to ask why I don't like it, I can't say a Kaniko. Maybe it's just a question of how to configure it. When using URL rewriter, configuration segments tend to be very long and each configuration item requires 4 lines of code from <RewriterRule> to </RewriterRule>, and a small project can easily have hundreds of lines of configuration. "It's too XML," I thought, "Why not use XML attribute?" So that each configuration item can be shortened to 1 lines--but this is a digression.