Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URL Masking

Posted on 2009-05-03
1
Medium Priority
?
267 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 1500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

971 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