Solved

How to use response.redirect in a custom class

Posted on 2008-11-03
19
1,321 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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