Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Server.Transfer in ASP.NET Core

I am migrating an ASP.NET application to ASP.NET Core and they have some calls to HttpServerUtility.Transfer(string path). However, HttpServerUtility does not exist in ASP.NET Core.

Is there an alternative that I can use? Or is Response.Redirect the only option I have?

I want to maintain the same behaviour as the old application as much as possible since there is a difference in between Server.Transfer and Response.Redirect.

like image 337
Connie Yau Avatar asked Sep 26 '16 00:09

Connie Yau


People also ask

Which one is better response redirect VS Server transfer?

So, in brief: Response. Redirect simply tells the browser to visit another page. Server. Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables.

What is difference between Server transfer and response redirect in C#?

The Response. Redirect method redirects a request to a new URL and specifies the new URL while the Server. Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.

What is the difference between Server transfer and Server execute?

Once code execution gets over, the control returns to the initial page, just after where it was called. However, in the case of Server. Transfer, it works very much the same, the difference being the execution stops at the new page itself (means the control isn't returned to the calling page).

Which method is used to redirect user from directly from Server?

Response. Redirect() sends a redirection header to the client , and the client itself requests the new page while the Server. Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.


1 Answers

I can see this is a fairly old thread. I don't know when URL Rewriting was added to .Net Core but the answer is to rewrite the URL in the middleware, it's not a redirect, does not return to the server, does not change the url in the browser address bar, but does change the route.

resources:

https://weblog.west-wind.com/posts/2020/Mar/13/Back-to-Basics-Rewriting-a-URL-in-ASPNET-Core

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting?view=aspnetcore-5.0

like image 72
Stu Avatar answered Sep 16 '22 13:09

Stu