Solved

How to use response.redirect in a custom class

Posted on 2008-11-03
19
1,315 Views
Last Modified: 2012-05-05
HI

I am using this code inside of a BLL Class:

            Try
                smtp.Send(correo)
                HttpContext.Current.Response.Redirect("pedido_completado.aspx")
            Catch ex As Exception
                'MsgBox("ERROR: " & ex.Message)
                HttpContext.Current.Response.Redirect("Error: " & ex.Message)
            End Try

And everything is working pretty well  (the mail is sent) except for the fact that when the line with the httpContext is executed appears a web page that informs "IE cannot show the page", just if the internet connection was lost.

¿Any ideas?

Thanks
0
Comment
Question by:dimensionav
  • 6
  • 6
  • 4
  • +1
19 Comments
 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865253
Hi,
What's the location of the  "pedido_Completado" web page?
If, for example, is in the root folder, it should be redirected like the following (note the ~/ at the beginning)
Response.Redirect("~/pedido_completado.aspx")
If it's inside some folder, just add the path, but make sure to have the ~ sign at the beginning. It tell asp.net to map the relative name of the web page to an absolute path.
 
0
 

Author Comment

by:dimensionav
ID: 22865366
HI Juan

I have tried but didn´t work
0
 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865389
Hi dimensionav,
Can you please tell me what's the path for  "pedido_completado.aspx", relative to the root folder?\
The error you are getting is because the file is not found, so we need to make sure that the path is corect.
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22865473
add system.web reference in your class and use this

HttpContext.Current.Response.Redirect("Your page")
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22865486
added to above try this to get url of your application
remoteUrl= ParseURL(context.Request.Url.AbsoluteUri);

and add your page name with string manipulation
0
 

Author Comment

by:dimensionav
ID: 22865526
Juan:

the path is the root app folder, and the BLL class files are inside App_Code/BLL

BondinASP, These are my class references:

Imports System.Web
Imports System.Data
Imports System.Data.OleDb
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports DAV.TiendaEnLinea.v1.DataAccessLayer

And this is the way I am calling response:

Try
   smtp.Send(correo)
  HttpContext.Current.Response.Redirect("pedido_completado.aspx")
Catch ex As Exception
   HttpContext.Current.Response.Redirect("Error: " & ex.Message)
End Try

0
 
LVL 7

Accepted Solution

by:
moseack earned 250 total points
ID: 22865626
Hello dimensionav,

I can give you three tips:
1) Don't run this code in your BLL, use a return value and do the Redirect in the GUI layer, it might solve the issue since I'm not sure URLs with '~' can be resolved in the BLL.
2) Redirect will try to end the processing of the request by Throwing "ThreadAbortException", so if you're catching this exception you might break the mechanism (http://msdn.microsoft.com/en-us/library/t9dwyts4.aspx)
3) Use Fiddler (http://www.fiddlertool.com/fiddler/) or smiler HTTP sniffer to see what is actually passed to the browser.
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22865699
>> the path is the root app folder, and the BLL class files are inside App_Code/BLL

right you need to replace this App_Code/BLL with your path .. suppose your page inside xyz foler so it should be ( inplace of  App_Code/BLL) xyz/yr pagename ..
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865710
moseack,
Using the HttpResponse object from a class is perfectly fine. I still think that the problem is that the path is incorrect, so, as you suggested, Fiddler is a good idea.

0
 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865732
BondinASP,
But the page is in the root folder, so both HttpContext.Current.Response.Redirect("pedido_completado.aspx") or HttpContext.Current.Response.Redirect("~/pedido_completado.aspx")should work.

0
 

Author Comment

by:dimensionav
ID: 22865750
I have tried resolving the URL trough the GUI layer and it worked, so I´ll try fiddler tomorrow.

I really appreciate your help guys!
0
 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865754
dimensionav,
What happens if you go to the browser and manually type http://yoursite/pedido_completado.aspx? Do you get the same IE error page?
0
 

Author Comment

by:dimensionav
ID: 22865776
it works, because pedido_completado.aspx is basically an advice that the email has been sent to the user´s account.
0
 
LVL 20

Expert Comment

by:Juan_Barrera
ID: 22865790
Then I have to say I'm lost, added to the fact that you say it's working from the GUI :).
I use Response.Redirect from my classes and never had this problem, and, besides, there is no reason for having it.  Anyway, I'm glad you get it working!
0
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22865886
Gud .. its working for you :)
0
 

Author Comment

by:dimensionav
ID: 23004468
HI Guys

I really sorry because I was on travelling...
Yesterday I have downloaded fiddler but I really didn´t know how to use it with VisualStudio 2005

your help will be appreciated.
0
 

Author Comment

by:dimensionav
ID: 23614675
Should I open a new question about using fiddler?

Regards.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now