Reputation: 3398
Please can anyone suggest me a better way on How to redirect to an ASPX page using a C# Class? The class has a method
protected void redirectTo() {
/*Code Here*/
}
When this method is called, I need to redirect the user to another page, How should i fill this method?
Upvotes: 1
Views: 2609
Reputation: 4081
You can use
Response.Redirect("Url.aspx");
Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History, ie it causes additional roundtrips to the server on each request. It doesn’t preserve Query String and Form Variables from the original request. Its a Response. Redirect simply sends a message down to the (HTTP 302) browser. Context.Items are lost when navigate to the new page.
or
Server.Transfer("Url.aspx");
Whereas, Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of new redirected page. It transfers current page request to another .aspx page on the same server. Data can be persist across the pages using Context.Item collection, which is one of the best way to transfer data from one page to another keeping the page state alive.
Upvotes: 0
Reputation: 17370
From another .aspx page:
Response.Redirect("Url.aspx");
From a class:
HttpContext.Current.Response.Redirect("Url.aspx");
Upvotes: 3
Reputation: 166326
Have a look at How to: Redirect Users to Another Page
Also HttpResponse.Redirect Method
Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
Upvotes: 0