2009-07-28 2 views
5

저는 고전 ASP에 익숙하지 않아 고객이 고전 ASP에 있기를 원하기 때문에 고전 ASP로 웹 응용 프로그램을 코딩해야합니다. 내가 클래스라는 사람의 목적이있을 때세션 객체의 기존 ASP 저장소 객체

:! 어쨌든 :(

여기 내 질문


지금까지 너무 좋아

Class Person 
Private m_sFirstName 

Public Property Get firstName 
firstName = m_sFirstName 
End Property 

Public Property Let firstName(value) 
    m_sFirstName = value 
End Property 

End Class 


set aPerson = new Person 
Person.firstName = "Danny" 

set Session("somePerson") = aPerson 
...

에 다음 요청과 같이 세션 바를 읽으려고합니다.

If IsObject(Session("aPerson")) = true Then 
    set mySessionPerson = Session("aPerson") 

     Response.Write(TypeName(myTest)) // will output "Person" 
     Response.Write(mySessionPerson.firstName) // will output "Object doesn't support this property or method: 'mySessionPerson.firstName' 
End If 

무슨 일이 일어나고 있는지에 대한 아이디어는 큰 도움이 될 것입니다.

답변

1

하지 작동하지 않는 코드가 나에게 잘 보이는 이유는 설명 할 수없는

If IsObject(Session("somePerson")) = true Then 
    set mySessionPerson = Session("somePerson") 
+0

ASP Classic의 개체를 직렬화 할 수 없으므로 상관 없습니다. –

+0

죄송합니다. 예제에서 엉망이되었습니다. –

+0

@Jeffery : ASP 및 sessionobject에는 "serialization"개념이 없습니다. – AnthonyWJones

3

이어야한다.

개체는 스크립트 컨텍스트에서 만들어지며 요청이 완료된 후에는 해체됩니다. 따라서 형식 이름을 사용할 수있는 동안 개체의 기능이 손상되었습니다.

스크립트에 생성되지 않은 객체라도 세션에 객체를 저장하는 것은 좋지 않다고 말할 수 있습니다.

ASP에서 사용되는 대부분의 개체는 단일 스레드에 있습니다. 생성 된 객체를 생성 한 스레드 만 객체에 액세스 할 수 있습니다. 이 문제에 대처하기 위해 일단 세션에 객체를 저장하면 ASP는 객체를 생성 한 특정 작업자 스레드와 세션을 연결합니다.

해당 세션에 대한 후속 요청이 도착하면 해당 작업자 스레드가 처리해야합니다. 해당 스레드가 다른 요청에 대해 작동 중이면 다른 사용 가능한 작업자 스레드가 충분하더라도 세션 요청이 대기합니다.

전반적인 효과는 작업 부하가 작업자 스레드에 고르지 않게 분산 될 수있는 응용 프로그램 확장 성을 손상시키는 것입니다.

+0

나는 이것을 보았다. 세션 및 응용 프로그램의 개체 수가 증가하면 성능이 저하됩니다. – ssorrrell

2

이렇게 할 수 있지만 약간 교활해야합니다. 내 이해는 당신이 세션에서 가정 구운 개체를 저장할 때 모든 데이터를 유지하지만 모든 기능을 잃는 것입니다. 기능을 다시 얻으려면 세션에서 데이터를 "재수 화"해야합니다.

ASP에 대한 JScript의 Heres는 예 : 필요한 경우

<%@ Language="Javascript" %> 
<% 

function User(name, age, home_town) { 

    // Properties - All of these are saved in the Session 
    this.name = name || "Unknown"; 
    this.age = age || 0; 
    this.home_town = home_town || "Huddersfield"; 

    // The session we shall store this object in, setting it here 
    // means you can only store one User Object per session though 
    // but it proves the point 
    this.session_key = "MySessionKey"; 

    // Methods - None of these will be available if you pull it straight out of the session 

    // Hydrate the data by sucking it back into this instance of the object 
    this.Load = function() { 
     var sessionObj = Session(this.session_key); 
     this.name = sessionObj.name; 
     this.age = sessionObj.age; 
     this.home_town = sessionObj.home_town; 
    } 

    // Stash the object (well its data) back into session 
    this.Save = function() { 
     Session(this.session_key) = this; 
    }, 

    this.Render = function() { 
     %> 
     <ul> 
      <li>name: <%= this.name %></li> 
      <li>age: <%= this.age %></li> 
      <li>home_town: <%= this.home_town %></li> 
     </ul> 
     <% 
    } 
} 

var me = new User("Pete", "32", "Huddersfield"); 
me.Save(); 

me.Render(); 

// Throw it away, its data now only exists in Session 
me = null; 

// Prove it, we still have access to the data! 
Response.Write("<h1>" + Session("MySessionKey").name + "</h1>"); 

// But not its methods/functions 
// Session("MySessionKey").Render(); << Would throw an error! 

me = new User(); 
me.Load(); // Load the last saved state for this user 

me.Render(); 

%> 

그 세션에 상태를 저장 관리하고 쉽게 DB를 위해 밖으로 swopped 수있는 아주 강력한 방법 등/XML 호출합니다.

앤서니가 스레드에 관해 제기 한 흥미로운 점은 자신의 지식의 깊이를 아는 것입니다. 나는 그 올바른 생각을 말합니다.하지만 소규모 사이트에서 벗어날 수 있다면, 우리는 이것을 실제적인 문제없이 수년간 중간 크기 위치 (일 당 10K 명의 방문자).

0

VB6에서 Person 클래스처럼 보이는 COM 개체를 만들 것입니다. 그런 다음 저장하십시오. 코드는 매우 유사합니다.

피트의 방법이 효과적 일 수 있습니다.

-1

나는 당신을 위해 그것을 테스트하는 게으른,하지만 대신

:

set Session("somePerson") = aPerson 

보십시오 :이 같은

Set Session("somePerson") = Server.CreateObject(aPerson) 
0

설정 세션 데이터 :

set Session.Contents("UserData") = UserData 

그리고 다음과 같이하십시오 :

Session.Contents("UserData.UserIsActive")