?
Solved

How to use response.redirect in a custom class

Posted on 2008-11-03
19
Medium Priority
?
1,345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

766 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