Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1377
  • Last Modified:

How to use response.redirect in a custom class

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
dimensionav
Asked:
dimensionav
  • 6
  • 6
  • 4
  • +1
1 Solution
 
Juan_BarreraCommented:
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
 
dimensionavAuthor Commented:
HI Juan

I have tried but didn´t work
0
 
Juan_BarreraCommented:
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!

 
Gyanendra SinghArchitectCommented:
add system.web reference in your class and use this

HttpContext.Current.Response.Redirect("Your page")
0
 
Gyanendra SinghArchitectCommented:
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
 
dimensionavAuthor Commented:
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
 
moseackCommented:
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
 
Gyanendra SinghArchitectCommented:
>> 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
 
Juan_BarreraCommented:
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
 
Juan_BarreraCommented:
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
 
dimensionavAuthor Commented:
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
 
Juan_BarreraCommented:
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
 
dimensionavAuthor Commented:
it works, because pedido_completado.aspx is basically an advice that the email has been sent to the user´s account.
0
 
Juan_BarreraCommented:
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
 
Gyanendra SinghArchitectCommented:
Gud .. its working for you :)
0
 
dimensionavAuthor Commented:
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
 
dimensionavAuthor Commented:
Should I open a new question about using fiddler?

Regards.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 6
  • 6
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now