Solved

URL Masking

Posted on 2009-05-03
1
247 Views
Last Modified: 2012-05-06
I have page name TestUrl.aspx when I execute this page I should display some random words in url, but I should not display the page name like TestUrl.aspx,
it should not be like
http://localhost:1156/WebSite3/mine/TestUrl.aspx
Please help me
Aspx File(Design File)

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <span style="font-size: 72pt">Url Masking</span></div>

    </form>

</body>

</html>
 
 

code file(cs file)

public partial class mine_TestUrl : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {
 

    }

}

Open in new window

0
Comment
Question by:mannevenu
1 Comment
 
LVL 2

Accepted Solution

by:
Cognize earned 500 total points
ID: 24293583
I think what you are refering to is commonly called URL rewriting. You need to check the request value in Application_BeginRequest in global.asax, which could be something like http://localhost/MyRenamedPage.aspx

You then use the Context.RewritePath( redirectString ); method to send the user to another resource as chosen by yourself - such as http://localhost:1156/WebSite3/mine/TestUrl.aspx

The Test.UrlRewriting.UrlRewriter.GetRedirectString( Request.Url.ToString(), Request.QueryString.ToString() ); method call in my code below is just a custom check for a predefined mapped URL.

Here you can see a good tutorial on url rewriting http://weblogs.asp.net/scottgu/


Fig.1
 

void Application_BeginRequest(object sender, EventArgs e)

    {

        //// Check if path is an alias for a real page. If so, rewrite path,

        //// else, allow user to continue to requested resource.
 
 

        

            string redirectString = Test.UrlRewriting.UrlRewriter.GetRedirectString( Request.Url.ToString(), Request.QueryString.ToString() );
 

            if ( redirectString != null )

            {

                Context.RewritePath( redirectString );

            }
 

    }

Open in new window

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now