locked
Using Response Object in Class as Page Soure - Doesn't WORK! RRS feed

  • Question

  • User1479866259 posted
    I am using the httpresponse object in a class for a protected area. The 'usermanager_doCheck' class is designed to do a check to see if the user is logged into the area. I set this as a source to a test page. The response object does not respond at all. I get no errors. imports system.web.ui.webcontrols imports system.web imports system.web.sessionstate Public Class usermanager_doCheck Sub Page_Load() Dim oSession As HttpSessionState = HttpContext.Current.Session Dim oRes as HttpResponse IF oSession("login_user_authenticated") = "true" THEN 'Do nothing ELSE oRes.redirect("###ERROR###.aspx") END IF End Sub End Class Thanks, Scott
    Tuesday, October 5, 2004 8:46 PM

All replies

  • User-1029435529 posted
    Try changing Dim oRes as HttpResponseto Dim oRes as HttpResponse = HttpResponse.Current
    Wednesday, October 6, 2004 12:58 AM
  • User1479866259 posted
    I get this compiler error: BC30002: Type 'HttpResponse.Current' is not defined.
    Wednesday, October 6, 2004 7:27 PM
  • User645477409 posted
    Yes, typo here, he meant HttpContext.Current.Response
    Wednesday, October 6, 2004 7:32 PM
  • User217889999 posted
    HttpResponse is mixed up with HttpContext here.
    Wednesday, October 6, 2004 7:33 PM
  • User1479866259 posted
    HttpResponse.Current does not work, I get the same error. As for httpcontext... I get this: Compiler Error Message: BC30311: Value of type 'System.Web.HttpResponse' cannot be converted to 'System.Web.HttpContext'. Source Error: Line 68: Sub Page_Load() Line 69: Dim oSession As HttpSessionState = HttpContext.Current.Session Line 70: Dim oRes as HttpContext = HttpContext.Current.Response Line 71: IF oSession("login_user_authenticated") = "true" THEN Line 72: '
    Wednesday, October 6, 2004 7:58 PM
  • User1479866259 posted
    None of this stuff worked... I checked on MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebhttpcontextclasstopic.asp)... It said the FULL control name must be addessed. I put this into the class. There is no error, however, it does not work.
    Wednesday, October 6, 2004 8:21 PM
  • User645477409 posted
    You did not read correctly, I said HttpContext.Current.Response Dim ores as HttpResponse = HttpContext.Current.Response
    Wednesday, October 6, 2004 9:33 PM
  • User1479866259 posted
    So far, I have this: Imports System Imports System.Web Imports System.Collections Imports System.Web.UI Imports System.Web.UI.HtmlControls Imports System.Web.UI.WebControls Imports Microsoft.VisualBasic Public Class usermanager_doCheck Protected Sub Page_Load(sender As Object, e As EventArgs) Dim myPage as Page = CType(sender, Page) IF system.web.httpContext.current.Session("login_user_authenticated") = "true" THEN ' ELSE mypage.Response.redirect("error.aspx?code=20") END IF mypage.response.write("this works!") End Sub End Class
    Wednesday, October 6, 2004 9:33 PM
  • User-1029435529 posted
    <color="#000000;width:550px;">Whoops ... sorry about that. Let me try that again. Change mypage.Response.redirect("error.aspx?code=20") to HttpContext.Current.Response.Redirect("error.aspx?code=20")And a similar update to the Response.Write line. (Whoops of course is a technical term that means my attention was diverted by the question of why the multiverse theory is so popular when the same phenomena can be explained by light travelling backwards through time; a much more palatable explanation.)</color>
    Wednesday, October 6, 2004 9:49 PM
  • User645477409 posted
    What same phenomena?
    Wednesday, October 6, 2004 9:54 PM
  • User217889999 posted
    What exactly are you trying to do here? You are using the Page_Load method, by is it wired up to anything? You are not Inheriting from the Page Class. Is this a Web Form we are looking at? As you don't seem to handle the Load Event of the Page Class here, I doubt if this Method is run at all...
    Wednesday, October 6, 2004 10:03 PM
  • User52920949 posted
    I know this is off topic, but you have piqued my curiousity. I am also interested to hear 'what same phenomena?'. The multiverse theory, as far as I am aware, is just a hypothesis based on the understanding that there is a predictable number of particles in our lightsphere, and that number can only have a finite number (x) of arrangements (finite being a loose term here because it's the only number I have ever seen that it is expressed as a power of a power). That being the case another lightsphere approximately x number of lightsphere's away should have an identical particle arrangement (an alternate, if not identcal, reality). I am not expecting to see this request posted, but it's been ages since I read anything on this subject so I am eager to hear of additional supporting phenomena if you know of any. Many thanks Martin
    Wednesday, October 6, 2004 10:29 PM
  • User-1029435529 posted
    <color="#6633cc;width:550px;">> What same phenomena?</color> <color="#000000;width:550px;">If memory serves, the genesis of the multiverse theory was the wave/particle duality of light. Light will act like a wave until observed, at which time it collapses to a point. To solve the riddle of Schrodinger's cat, it was proposed that wherever an elemental "decision" is made (whether the light went through the top or bottom hole of the twin-hole experiment; or whether Schrodinger's cat is alive or dead), the universe splits to accommodate both decisions. In one universe, the cat is alive; in the other, the cat is dead. Another "solution" to the riddle proposed by Schrodinger's cat is the idea that light travels backwards in time, just as it travels forward. I can't recall the details of this solution (I read it more than five years ago), but I think it was along the lines that a quantum of light is not moving forwards through time in an uncertain state. Rather, because it can move forward and backward in time, it instead moves forward in a certain state; certain of its future, having already been there. The cat was dead or alive when the box was sealed, not when it was opened. This removes the importance of the observer, which had raised its own set of hard questions ... who is an observer? and who is observing the observer (which is necessary for the observer to have been there in the first place)? By removing the observer as a participant who collapses uncertainty to certainty, there is again no need for multiverses (alternative certainties following the uncertainty). I know that the multiverse theory has moved on from that, and rather than splitting universes there are now bubbling multiverses and virtual multiverses. But the wave/particle genesis stays the same, and that was the phenomena I was talking about. Maybe I need to get a modern quantum physics book?</color>
    Wednesday, October 6, 2004 10:59 PM
  • User1479866259 posted
    This is extremley confusing.... All I need to know how to do is to retrieve a session varible and redirect the user to a spaecific page in a class and include this class as the source of an aspx page.
    Wednesday, October 6, 2004 11:31 PM
  • User-1029435529 posted
    <color="#000000;width:550px;">I've just re-read my post, and can already see it contains some sillyness. I kept saying "the riddle proposed by Schrodinger's cat" ... it would have been more correct to say "the problem of Copenhagen indeterminism, as exemplified by Schrodinger's cat". And I last read a quantum physics book about five years ago. That puts my understanding back in the middle ages of science. My explanation of "whoops" was only meant to be comical :)</color>
    Wednesday, October 6, 2004 11:33 PM
  • User1479866259 posted
    If I may comment, Quauntum Physics might be a little of topic.
    Wednesday, October 6, 2004 11:36 PM
  • User52920949 posted
    Some readers are going to get peeved by how off topic this thread has become but... I never did like using the cat experiment for a demostration of the uncertainty principle. I mean Schrodinger was trying to explain the role of the observer in deciding the quantum state of a particle. In his experiment he assumed that the only observer was the experimenter that opened the box - until the box was opened the particle was 'in' a state of quantum uncertainty. But, what I always say when someone mentions the experiment - what about the cat???!!! Surely, it knows whether it is alive or dead! Quantum uncertainty may very well be a real phenomenon but the demonstration is worse than being human-centric (the kind of thinking that led to 'the earth is the center of the Universe' thinking), but is experimenter-centric. Anyways, to bolster your consideration of reverse time light travel, think of this - time slows down the closer to the speed of light you get. So, if you reach the speed of light, time stops. Light is always travelling at the speed of light. Quid pro quo, light does not experience time. From it's perspective it is absorbed at the same time as it is ommitted - it doesn't exist! ;-) Yes, I am crazy... Martin
    Wednesday, October 6, 2004 11:48 PM
  • User1479866259 posted
    This is absolutley absurd - IS IT IMPOSSIBLE TO DO WHAT I AM ATTEMPTING OR NOT?????????
    Wednesday, October 6, 2004 11:56 PM
  • User-1029435529 posted
    <color="#6633cc;width:550px;">> If I may comment, Quauntum Physics might be a little of topic.</color> <color="#000000;width:550px;">Quite right. Sorry. And it must have been frustrating for us to talk about cats when you have more pressing concerns. By way of apology, I've created a little sample app for you. You can view it here: www.edition3.com/developers/scott_ttocs46 The code is available here: code.zip I've tried to mimic what you're doing ... putting the security stuff into a class that is separate from the codebehinds. If you run the app online, and then view the codebehinds and security class, you should be able to fit the ideas into your own system. I think, however, that you should consider using Forms Authentication. It's not a good idea to put authentication or authorization into Session variables. What happens if the boss goes out to lunch, and then returns to your app? The session will have expired, and with it his authentication and authorization. Forms Authentication overcomes this by adding any roles into an encrypted cookie. Anyway, sorry for the tangent, and I hope that the above helps.</color>
    Thursday, October 7, 2004 12:32 AM
  • User-1029435529 posted
    <color="#000000;width:550px;">Apparently though, it makes no sense to say that time stops when you go at the speed of light. Yet apparently it is still true to say that the photon sees neither a past nor a future. For the duration of its existence, it "knows all". While the stationary observer with his pocket protector sees a photon moving forward through time, and wonders which hole it will go through ... the same photon at the observer's point in time already knows what occurs in the observer's future. The observer is playing no part in the proceedings, he's almost watching a delayed telecast. While I'm aware that this has implications regarding our "freedom of choice", I still find this a much more palatable solution to indetermination than multiverses. Sure, science doesn't care what is palatable ... but it helps me sleep. Who brought up this dumb topic, anyway? :} </color>
    Thursday, October 7, 2004 1:03 AM
  • User89687413 posted
    Hey, I ‘m new to this. But I am learning. Now, I use WebMatrix and have a couple of questions. I like to make a login screen validated on a SQL server ( no problem ) Now I like to make something so users must go to the login Page and not go directly to a page. Maybe SessionID is a good thing to compare to. Now I need the session var. on other page’s to check. Cookies are disabled by System administrators. I believe also in the class you created. But how do I get the var.. I am using this structure on IIS and the page’s are on different folders (aspx files ) Root | |_Windsurf | | | |_Login (Folder) | | |_Login.aspx | |_StockItems (Folder) | |_Search.aspx | So, the var (session.sessionID ) must come from Login.aspx to search.aspx Can you help me ?
    Thursday, October 7, 2004 1:05 PM
  • User-1029435529 posted
    <color="#000000;width:550px;">Can I ask that you create a new thread with your question? This thread has already gone off on one tangent, and we should leave the remainder of it to ensure scott_ttocs46 gets the help s/he needs.</color>
    Thursday, October 7, 2004 1:23 PM
  • User1479866259 posted
    SomeNewKid, I appreciate your help. My prob is fixed. Thanks, Scott
    Thursday, October 7, 2004 7:33 PM
  • User645477409 posted
    Glad to hear that your problem is solved. For those who are interested in the off-topic dicussion on quantum physics, here's something I just wrote about it: A few things I remember about quantum mechanics.
    Thursday, October 7, 2004 10:08 PM
  • User89687413 posted
    Sorry
    Friday, October 8, 2004 4:42 AM
  • User-1029435529 posted
    <color="#6633cc;width:550px;">> here's something I just wrote about it</color> <color="#000000;width:550px;">Sheesh, had I realised that the audience contained those whose PhD involved quantum mechanics, and others who majored in maths, I would have said that "whoops" was a technical term for "I wasn't thinking too clearly"! That would have been more honest, too :)</color>
    Sunday, October 10, 2004 8:45 AM
  • User1479866259 posted
    Here's a quicker way of doing it: After declaring the class, append the following: Inherits System.Web.UI.Page Use the controls like you are programming in the page.
    Wednesday, November 10, 2004 7:16 PM
  • User645477409 posted
    Eeeek! That doesn't look like a good idea. HttpContext.Current is not that hard.
    Wednesday, November 10, 2004 8:25 PM
  • User-1029435529 posted
    <color="#000000;width:550px;">Not only is HttpContext.Current not hard, it is perhaps the most powerful object in ASP.NET. It allows you to access almost everything ... the Request, the Response, the User, the Application, the Cache, and the Session. It also works to give you a very efficient per-request data store. ASP.NET v2.0 extends this object, giving it even more power. This object is also available before the request ever makes it to your .aspx handler, and is still available after your .aspx handler has finished. This object is so powerful, yet so infrequently discussed, that I think it's perhaps ASP.NET's best-kept secret. Don't shy away from the HttpContext.Current object.</color>
    Wednesday, November 10, 2004 9:25 PM