What is the best approach for redirecting a user to asp.net?

I am new to asp.net development.I am currently running an asp.net web application. When resolving the problem, the exception "thread is interrupted." I went through several articles to get a deep understanding of the exception.

I read this wonderful article in the Shivprasad koirala code project that explained to me about using Server.Transfer and Response.Redirect .

Then I went to this post by Thomas Marquardt which made me conclude Respose.Redirect(url,false) , but it’s better to use

 Server.ClearError(); Response.Redirect(url, false); Context.ApplicationInstance.CompleteRequest(); 

But again this article from Imrambaloch there is a security issue with Response.Redirect(url, false) and use instead

 Response.Redirect(url, false); var context = HttpContext.Current; if (context != null) { context.ApplicationInstance.CompleteRequest(); } 

Now, in the end, I'm a little confused, as this is the recommended redirection method.

My question is: How can I redirect the user to troubleshooting security and performance issues?

Is Server.Transfer really that bad compared to Response.Redirect ?

+7
source share
3 answers

Adding to @William's answer:

The Server.Transfer method does not change the URL in the browser, but redirects the user to a new page. It stores information about the previous page on the server, and Response.Redirect is completely redirected without saving the state of the last page.

For performance, Response.Redirect has a different argument to endResponse (bool). Passing the truth in the second argument may make your application slow, since EndResponse () is not recommended, even if you do it manually to complete the response. Rather, use Context.ApplicationInstance.CompleteRequest (), as suggested by the blogs you have listed.

+4
source share

As you probably read about the messages you delivered, Response.Redirect transmission is performed by the browser, and with Server.Transfer is performed on the server.

Use Server.Transfer when you want to go to pages that are on the same server, and use Response.Redirect when you want to navigate between pages that are on different servers / domains.

Server.Transfer is faster because there are fewer round-trip calls - it saves server resources.

Bottom line - it depends on your requirements.

+2
source share

Short answer: do what the first article says.

Although technically correct, the second article discusses the simplest solution: avoid executing Response.Redirect in Page_Load. If you have to pull Response.Redirect into Page_Load, just click on ThreadAbortException for this one or two instances, rather than write a bunch of stupid code in the HttpModule.

Generally speaking, you probably don't have too many good reasons to pull Response.Redirect into Page_Load anyway.

For example, if you use ASP.NET Forms authentication, this will ensure that you are not here, go to this friend on the login page.

As an additional note, if you have the opportunity to do this, focus on ASP.NET MVC technology. This will help you improve your work and less frustration as you advance your career.

+1
source share

All Articles