Solved

How to use response.redirect in a custom class

Posted on 2008-11-03
19
1,325 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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
 
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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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