473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

REdirecting

Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama
Nov 18 '05 #1
10 1343
Dont redirect from within the component. Such decisions belong in the upper
application layer. Simply raise the exception in the case below, and let
the layer above deal with how to report the error.

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama

Nov 18 '05 #2
Hi Nick,

How would I know it threw an exception? How can I validate for it? I don't
want the web to crash. I would rather return a descriptive error message to
the user.

Yama

"Nick" <fr**@here.there> wrote in message
news:uY****************@TK2MSFTNGP10.phx.gbl...
Dont redirect from within the component. Such decisions belong in the upper application layer. Simply raise the exception in the case below, and let
the layer above deal with how to report the error.

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama


Nov 18 '05 #3
Yama Try this
Use
Response.Redirect("page.aspx",false)

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

' you can use Response.Redirect("Page.aspx") here like this
Response.Redirect("Page.aspx",false)

Trace.Write(ex.Message)

Finally

End Try

Reason is Try & Catch will work under a thread. So if it will not execute end try this thread is not aborted. Before that if you try to redirect a open thread it will throw error. For aborting this single thread use Response.redirect's second parameter to false.

this will abort your try single thread and move on to redirected page.

Default Response.redirect has 2nd parameter as true.

if you want to see the detail of error case

you can do this
Response.redirect("page.aspx?errText=" & e.tostring",false)

in your page.aspx

you can print

Response.write(Request.querystring("errText")

Nov 18 '05 #4
Can you redirect using the web.config?
"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama

Nov 18 '05 #5
Explain it more. Why did you want to use web.config here?
Nov 18 '05 #6
Joji,

Thank you for your reply. But because I am trying to redirect from a class
that is not implemented with System.Web.UI.Page I do not have access to the
PAge namespace.

I tried some like this:

Private PageUI As System.Web.UI.Page
PageUI.Response.Redirect("gfdgdg.aspx")

But it didn't work!

The problem I am having is that I am trying to redirect directly from a
class. Is it at all possible?

Yama

"Joji" <an*******@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
Explain it more. Why did you want to use web.config here?

Nov 18 '05 #7
Yama,

You must have made a call into your component/class from within a web page?
In the web page do the following:

public void SomeMethodCall()
{
try
{
YourClass class = someFactory.GetClass(); // However you acquire an
instance of the class
class.CallTheMethodYouNeed(withDataYouRequire);
}
catch(Exception e)
{
Response.Redirect("error.aspx", ....etc);
}
}

I am sure most here will agree that coupling your class to the web
infrastructure is simply not a good choice. It is best the class is
agnostic to the host (if it is a business component which is what I have
assumed). If you really do need to have the class perform the redirect,
pass in the HttpContext object to the business component.

HTH

Nick.

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Joji,

Thank you for your reply. But because I am trying to redirect from a class
that is not implemented with System.Web.UI.Page I do not have access to the PAge namespace.

I tried some like this:

Private PageUI As System.Web.UI.Page
PageUI.Response.Redirect("gfdgdg.aspx")

But it didn't work!

The problem I am having is that I am trying to redirect directly from a
class. Is it at all possible?

Yama

"Joji" <an*******@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
Explain it more. Why did you want to use web.config here?


Nov 18 '05 #8
Hi all,

Well here is the way I settled for:
In my web.config file I added the following:
----------------------------------------------------------------------------
<customErrors mode="remoteOnly" defaultRedirect="error.aspx" />

<!-- You can configure the custom errors to be On, Off, or RemoteOnly. On
means everyone sees it. Off means no one sees the custom errors.
RemoteOnly means that any off the box will see the custom error page and
anyone on the box will see the real stack trace. -->

<error statusCode="404" redirect="NotFound.aspx" />
<error statusCode="403" redirect="AccessNotAllowed.aspx" />
<error statusCode="500" redirect="InternalError.aspx" />
<!-- etc... -->
----------------------------------------------------------------------------
I am sure you'll love this feature... Particularly the first line:
customErrors

Yama Kamyar
"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama

Nov 18 '05 #9
Hi all,

Another good one is writing into your Global.asax file to handle an error
such as:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

Dim oMail As New MailMessage

oMail.To = "ya**@mydotcom.com"

oMail.Cc = "ya**@mydotcom.com"

oMail.From = "Admin"

oMail.Subject = "Unhandled Error!"

oMail.BodyFormat = MailFormat.Html

oMail.Body = "<html><body><h1>" & Request.Path & _

"</h1>" & "</body></html>"

SmtpMail.Send(oMail)

End Sub

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama

Nov 18 '05 #10
Hi,

You may want to ADD the following lines of code:

Imports System.Web.Mail
SmtpMail.SmtpServer.Insert(0, "MyExchangeServerName")

before SmtpMail.Send(oMail)

Yama

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi all,

Another good one is writing into your Global.asax file to handle an error
such as:

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

Dim oMail As New MailMessage

oMail.To = "ya**@mydotcom.com"

oMail.Cc = "ya**@mydotcom.com"

oMail.From = "Admin"

oMail.Subject = "Unhandled Error!"

oMail.BodyFormat = MailFormat.Html

oMail.Body = "<html><body><h1>" & Request.Path & _

"</h1>" & "</body></html>"

SmtpMail.Send(oMail)

End Sub

"Yama" <yk*****@grandpacificresorts.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

How can I redirect to an error page from a component vb.net?

Public Class bo

Protected Friend Function CreateString(ByRef lst As ListBox) As String

dim s As String

Try

s = "Hello World"

' create a new dataset

Catch ex As Exception

' How can I use Response.Redirect("page.aspx") from here???

Trace.Write(ex.Message)

Finally

End Try

Return s

End Function

End Class

Thanks,

Yama


Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ivo Woltring | last post by:
Hi Pythoneers, I am trying to make my own gui for mencoder.exe (windows port of the terrific linux mencoder/mplayer) to convert divx to Pocket_PC size. My current app creates a batch script to...
10
by: Kenneth Keeley | last post by:
Hi, I have been having problems with Gecko based browsers not redirecting properly. This is the line of code that does the redirecting: Response.Redirect ("Validation.asp?BookingNo=1234567") ...
0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
3
by: lozd | last post by:
Would appreciate any solutions people could offer for this. Basically I wan't to use a frameset with an aspx page as the contents rather than a htm page and I'd like to be able to redirect the...
0
by: Sune Hansen | last post by:
Hi guys, I really hope someone can help me with my problem. Here is the scenario: I have a development environment on my locale machine. Once in a while when everything has been tested I...
1
by: Bilbo | last post by:
Hello, How do I programatically redirect a page in "another frame" using C# in ASP.NET? Server.Transfer redirects the current page...not a different frame. Thanks.
3
by: tony | last post by:
I've been searching through the threads to find a solution for 401.3 error triggered by windows authentication not being able to redirect to a custom error page to no avail. It seems that ASP.NET...
4
by: Greg Smalter | last post by:
Redirecting from page to page within a web project is pretty easy. However, all Redirect methods take strings as arguments, as if you mistype the string, you don't find out until run time that you...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
17
by: mansb2002 | last post by:
Hi, We recently moved our webserver from Win2K to Win2003. The application works fine. Only problem is that when user views a report as a PDF, IE does not show it. The following code is used to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.