Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
HttpContext Class
 RewritePath Method (String, String,...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HttpContext..::.RewritePath Method (String, String, String, Boolean)

Updated: July 2009

Rewrites the URL using the given virtual path, path information, query string information, and a Boolean value that specifies whether the client file path is set to the rewrite path.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Sub RewritePath ( _
    filePath As String, _
    pathInfo As String, _
    queryString As String, _
    setClientFilePath As Boolean _
)
Visual Basic (Usage)
Dim instance As HttpContext
Dim filePath As String
Dim pathInfo As String
Dim queryString As String
Dim setClientFilePath As Boolean

instance.RewritePath(filePath, pathInfo, _
    queryString, setClientFilePath)
C#
public void RewritePath(
    string filePath,
    string pathInfo,
    string queryString,
    bool setClientFilePath
)
Visual C++
public:
void RewritePath(
    String^ filePath, 
    String^ pathInfo, 
    String^ queryString, 
    bool setClientFilePath
)
JScript
public function RewritePath(
    filePath : String, 
    pathInfo : String, 
    queryString : String, 
    setClientFilePath : boolean
)

Parameters

filePath
Type: System..::.String
The virtual path to the resource that services the request.
pathInfo
Type: System..::.String
Additional path information to use for the URL redirect.
queryString
Type: System..::.String
The request query string to use for the URL redirect.
setClientFilePath
Type: System..::.Boolean
true to set the file path used for client resources to the value of the filePath parameter; otherwise false.
ExceptionCondition
ArgumentNullException

The path parameter is not in the current application's root directory.

HttpException

The filePath parameter is not in the current application's root directory.

The filePath parameter does not include the content of the pathInfo parameter. For the URL http://www.microsoft.com/virdir/page.html/tail, the filePath parameter is http://www.microsoft.com/virdir/page.html, and the pathInfo parameter is tail.

To ensure that the virtual path that is used to construct paths to resources is not modified, set the setClientFilePath parameter to false. A common scenario in which you might want to set setClientFilePath to false is when you need to rewrite the URL, and you are using themes and redirecting the URL to a resource located in a different folder than the requested resource.

URL rewriting is useful when you want to restructure the pages in your Web application, and you want to make sure that people who have bookmarked old URLs can still use them after you have moved pages. URL rewriting enables you to transparently forward requests to the new page location.

If you want to enable a site to use URLs that are more user-friendly and are optimized for search engines, a more robust alternative is to use ASP.NET routing. For more information, see ASP.NET Routing.

For a code example, see the RewritePath(String) method overload.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Date

History

Reason

July 2009

Expanded explanatory comments.

Customer feedback.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker