[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Response is not available in this context.

Posted on 2010-11-23
8
Medium Priority
?
806 Views
Last Modified: 2012-06-22
Hi Experts,

I call a subroutine in a class to set some session variables, the following code is within a try, however, an exception is raised (Response is not available in this context.) when I try to redirect to this page Response.Redirect("CreateNewProject.aspx"), why is this and what am I doing wrong?

Try
            'create new dataset to read the xml in the customer config table into.
            Dim dsxml As New DataSet
            dsxml.ReadXml(Session.Item("customerConfigFilePath"))
            Dim userNameStr As String = "UserName = '" & userName & "'"

            'search for the user row based on thier username
            Dim dataRows As DataRow() = dsxml.Tables(0).Select(userNameStr)

            If dataRows(0).Item("NumberOfLogins") = 1 Then
                Response.Redirect("CreateNewProject.aspx")
            Else
                'set session variables
            Endif

 Catch ex As Exception
            l.writeToLogFile(Session.Item("customerLogFile"), "[Error #0031] Could not setup the session variables " & ex.Message.ToString)
        End Try
0
Comment
Question by:MOSSPOINT
[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
  • 4
  • 4
8 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 34197593
If you need access to the Response object outside the Page, use this:
HttpContext.Current.Response
0
 

Author Comment

by:MOSSPOINT
ID: 34197676
I'm not sure I understand, could you re-write the code example I included with your idea to show me how to do it?
0
 
LVL 32

Expert Comment

by:Erick37
ID: 34197705
The section of code to be modified:

            If dataRows(0).Item("NumberOfLogins") = 1 Then
                ''Use HttpContext.Current.Response here:
                HttpContext.Current.Response.Redirect("CreateNewProject.aspx")
            Else
                'set session variables
            Endif

More information here:
"Working With HttpContext.Current"
http://odetocode.com/Articles/112.aspx
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:MOSSPOINT
ID: 34197843
Eric,

I made that change and now I get the following exception, any ideas?

System.Threading.ThreadAbortException = {Property evaluation failed.}
0
 
LVL 32

Expert Comment

by:Erick37
ID: 34198002
It appears that we need to set the second parameter of Redirect to False.
Give this a try:

            If dataRows(0).Item("NumberOfLogins") = 1 Then
                ''Use HttpContext.Current.Response here:
                HttpContext.Current.Response.Redirect("CreateNewProject.aspx", False)
            Else
                'set session variables
            Endif

Documentation
http://support.microsoft.com/kb/312629/EN-US/ 
0
 

Author Comment

by:MOSSPOINT
ID: 34200641
Eric,

The line HttpContext.Current.Response.Redirect("CreateNewProject.aspx", False) does not throw an exception this time but neither does it redirect to the CreateNewProject.aspx page.

Any ideas?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 34201974
Not sure why, I was able to redirect using the following.
The class code follows.  Notice I have 2 ways to redirect, Redirect1 uses the Page.Response.Redirect() and Redirect2 uses HttpContext.Current.Response.Redirect().  Both seem to work for me in my sample application.

Utilities.Redirect1(Me.Page)

and

Utilities.Redirect2()


Public Class Utilities

	Public Shared Sub Redirect1(ByVal page As Page)

		page.Response.Redirect("webform1.aspx", False)

	End Sub

	Public Shared Sub Redirect2()

		HttpContext.Current.Response.Redirect("webform1.aspx", False)

	End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:MOSSPOINT
ID: 34203244
Thanks
0

Featured Post

Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
Suggested Courses

649 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