简体   繁体   中英

Response.Redirect() or A HREF ?

I see a lot of articles talking about how to use it. But what is the advantage of using Response.redirect in your c#, versus just using ahref in the .aspx file?

Response.Redirect runs on the ASP.NET Server. It can only be using when the server is processing an existing HTTP request. It sends a redirect status code and location to redirect back to the client as part of an HTTP response. Then client can then take that location and send an HTTP request to it. So you end up with:

Client -> Server: Initial request for resource at location X
Server -> Client: Redirect to get resource from location Y
Client -> Server: Request for resource at location Y

A hyperlink (a href) is before any HTTP request is even generated. When you click on a hyperlink, the browser just sends an HTTP request to the location specified by the href. The browser could then response with a redirect.

They're really apples and oranges, because they operate at different times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM