Articles → .NET → URL Rewriting Using Httpmodules
URL Rewriting Using Httpmodules
- Visual studio installed on your machine.
- Have the hands on experience in creating web application.
- Have knowledge of HTTP modules.
- Create a web application and name it say URLRewriting.
- Add a class and inherit the class with IHttpModule interface.
- Now the class has implemented the IHttpModule interface then the class must implement 2 methods Init and Dispose.
- In this init method add an event handler and name it let us say Rewrite_BeginRequest. So the definition of Init function would be
- When you create a web application a file default.aspx is created in it. Now add another file called Default2.aspx(you can name anything you want).
- Add a 2 buttons in Default.aspx.
- On button click event add the following code.
- Now go back to UrlRewriter class and add code to Rewrite_BeginRequest event. So the code would be
- Now it is the time to register the HTTPmodule in web.config file. Add the following code in web.config file.
- On default2.aspx write the following code
Click to Enlarge