Easiest way to remove .aspx from url in asp.net

Category > ASP.NET || Published on : Thursday, November 5, 2015 || Views: 2133 || Easiest way to remove .aspx from url in asp.net Easiest way to remove .aspx


In this tutorial we are going to learn and understand Easiest way to remove .aspx from url in asp.net.

Step 1: Create a asp.net web page(aspx page) name default.aspx with the follwoing codes:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
<div>
    <h1>This is Home Page</h1>
</div>
<a href="About.aspx">Go to About Page</a>
    </form>
</body>
</html>

Step 2: Create a global.asax file with the following codes:-

<%@ Application Language="C#" %>

<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);

    }

    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown

    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>

Step 3:Create a asp.net webpage (About.aspx) with the following :-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h1>This is about us page.</h1>
            <a href="Default.aspx">Go to Home Page.</a>
        </div>
    </form>
</body>
</html>

Step 4: Add the Install Nuget package command in the nuget console.

Install-Package Microsoft.AspNet.FriendlyUrls

it will add the required files like below

Easiest way to remove .aspx from url in asp.net

Result Screenshots are below

In this tutorial we have learned how to Easiest way to remove .aspx from url in asp.net