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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more