URL REWRITING IN ASP.NET (OR) HOW TO HIDE .ASPX(VS 2012 OR VERSION 4.5)
This article how to hide .aspx in version 4.5
step:1
visual studio 2012--> file--->new project--->solution explore---> add reference--->system.web.routing
step:2
solution explore--->add new item--->global.asax
step:3
global.asax
first you declare RegisterRoutes() in application_start:
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
step:4
after you create how to hide the .aspx extension in RegisterRoutes();
(any description mens you create any value)
private static void RegisterRoutes()
{
System.Web.Routing.RouteTable.Routes.Add("Any Description",
new System.Web.Routing.Route("contact", new
PageRouteHandler("~/contact.aspx")));
System.Web.Routing.RouteTable.Routes.Add("Any Description1",
new System.Web.Routing.Route("home", new
PageRouteHandler("~/home.aspx")));
}
step:5
now you create home.aspx and contact.aspx
this home.aspx
now you redirect contact.aspx but already you declare global.asax contact .aspx means contact
contact.aspx
contact.aspx.cs
now run the application
global.asax
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Routing;
namespace hideextenstion
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
private static void RegisterRoutes()
{
System.Web.Routing.RouteTable.Routes.Add("Any Description",
new System.Web.Routing.Route("contact", new
PageRouteHandler("~/contact.aspx")));
System.Web.Routing.RouteTable.Routes.Add("Any Description1",
new System.Web.Routing.Route("home", new
PageRouteHandler("~/home.aspx")));
}
}
}
home.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="hideextenstion.home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="d" runat="server" Text="contact" OnClick="d_Click" style="height: 26px" />
</div>
</form>
</body>
</html>
home.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace hideextenstion
{
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void d_Click(object sender, EventArgs e)
{
Response.Redirect("contact");
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="contact.aspx.cs" Inherits="hideextenstion.contact" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="d" runat="server" Text="Home" OnClick="d_Click" style="height: 26px" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace hideextenstion
{
public partial class contact : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void d_Click(object sender, EventArgs e)
{
Response.Redirect("home");
}
}
}
download this application:Hide .aspx extenstion