Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HttpContext.RewritePath Method (String, Boolean)

Rewrites the URL using the given path and a Boolean value that specifies whether the virtual path for server resources is modified.

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

member RewritePath : 
        path:string * 
        rebaseClientPath:bool -> unit

Parameters

path
Type: System.String

The internal rewrite path.

rebaseClientPath
Type: System.Boolean

true to reset the virtual path; false to keep the virtual path unchanged.

ExceptionCondition
ArgumentNullException

The path parameter is a null reference (Nothing in Visual Basic).

HttpException

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

The HttpContext.RewritePath(String, Boolean) method is called by the HttpContext.RewritePath(String) method with the rebaseClientPath parameter set to true. To ensure that the virtual path that is used to construct paths to resources is not modified, set the rebaseClientPath parameter to false. A common scenario in which you might want to set rebaseClientPath 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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
Show:
© 2015 Microsoft