DEV Community

Sardar Mudassar Ali Khan
Sardar Mudassar Ali Khan

Posted on

URL rewrite in Asp.net Web Forms for Specific Pages

In ASP.NET Web Forms, you can use URL rewriting to modify or prettify the URLs of specific pages. URL rewriting allows you to present cleaner and more user-friendly URLs to your website visitors while internally mapping those URLs to the actual physical pages on the server.

To implement URL rewriting for specific pages in ASP.NET Web Forms, you can follow these steps:

Step 1: Install the URL Rewrite module
If you haven't already installed the URL Rewrite module, you'll need to do so. You can download it from the official Microsoft website or through the Web Platform Installer.

Step 2: Configure the rewrite rule
Once the URL Rewrite module is installed, you can add rewrite rules to your web.config file to specify how the URLs should be rewritten.

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Rewrite to Clean URL">
        <match url="^specific-page-url$" />
        <action type="Rewrite" url="actual-page.aspx" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>
Enter fullscreen mode Exit fullscreen mode

In the above example, specific-page-url is the URL you want to present to the user, and actual-page.aspx is the physical page on the server that should handle the request. Adjust these values according to your specific requirements.

Step 3: Test the rewritten URL
Save the web.config file and test the rewritten URL in a browser. When a user navigates to specific-page-url, the server will internally route the request to actual-page.aspx without changing the URL displayed in the browser.

You can add multiple rewrite rules for different pages as needed. Make sure to adjust the URL patterns and corresponding physical pages in the rewrite rules accordingly.

Remember to also consider any SEO implications when implementing URL rewriting, such as maintaining proper redirection and avoiding duplicate content issues.

Note: URL rewriting in ASP.NET Web Forms is typically used for simple scenarios. For more complex routing requirements, you might want to consider using ASP.NET MVC or ASP.NET Core, which provide more advanced routing capabilities out of the box.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay