How to display extension aspx in asp net

Introduction

ASP.NET is a popular language used for web applications. One common requirement in web development is to display the extension “.aspx” in the URL of ASP.NET pages. In this article, we will explore different approaches to this.

Approach 1: URL Rewriting

URL rewriting is a technique that allows you to modify the URL of a web page without changing the page. This can be achieved the System.Web.Routing namespace in ASP.NET.

To display the extension “.aspx” in the URL, you can define a route in the RouteConfig.cs file as follows:


public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("Default", "{page}.aspx", "~/Default.aspx");
}

This route configuration maps any URL with the extension “.aspx” to the Default.aspx page. For example, if you have a page named .aspx, it can be accessed using the URL http://example.com/About.aspx.

Approach 2: URL Rewrite Module

approach to display the extension “.aspx” in the URL is by using the URL Rewrite Module in IIS (Internet Services).

To achieve this, you need to the URL Rewrite Module in IIS and then a rewrite rule. The rewrite rule should match the URL pattern without the extension and redirect it to the corresponding ASP.NET page with the extension.

Here is an example of a rewrite rule in the web.config file:



    
        
            
            
                
                
            
            
        
    

This rewrite rule matches any URL pattern and appends the “.aspx” extension to it. For example, if you have a page named About.aspx, it can be accessed using the URL http://example.com/About.

Conclusion

Displaying the extension “.aspx” in the URL of ASP.NET pages can be achieved using URL rewriting or the URL Rewrite Module in IIS. Both approaches provide a way to modify the URL without changing the actual page. Choose the approach that best suits your requirements and project setup.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents