Export (0) Print
Expand All

HttpContext.RewritePath Method (String)

Rewrites the URL using the given path.

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

public void RewritePath (
	string path
)
public void RewritePath (
	String path
)
public function RewritePath (
	path : String
)
Not applicable.

Parameters

path

The internal rewrite path.

Exception typeCondition

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 RewritePath method redirects a request for a resource to another resource without changing the URL. If you need to reset the virtual path so that client resources resolve correctly, use the overload of this method that takes the rebaseClientPath parameter and set the parameter to false.

The following example demonstrates how to rewrite the internal path to send the client to another page.

void Button_Click(Object sender,EventArgs e)
{      
   Response.Write("Data submitted to this page");    
}
     
void Page_Load(Object sender,EventArgs e) 
{
 
   // Rewrite the internal path to send the client 
   // to the page passed to the RewritePath method.            
   Context.RewritePath("HttpContext_Next.aspx");        
}

void Button_Click(Object sender,EventArgs e)
{      
   get_Response().Write("Data submitted to this page");    
} //Button_Click
     
void Page_Load(Object sender,EventArgs e) 
{
   // Rewrite the internal path to send the client 
   // to the page passed to the RewritePath method.    

   get_Context().RewritePath("HttpContext_Next.aspx");        
} //Page_Load

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft