-1

私はaspページを持っています。クエリ文字列から値を取得し、セッションに保存します。 コードは

username = Trim(Request.querystring("username"))
Session("login")=username
NewUserName=Session("login")

ここで、Asp.vb ページ コードでこの NewUserName 値にアクセスしたいと思います (.aspx ページ)

<script type="text/javascript" language="javascript">

var login = '<%= Session["NewUserName"].ToString(); %>';
Session("login")=Login;
alert(login);

</script>

コードは (.aspx.vb)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



Login = Session("login")
    If Session("login") Is Nothing Then
        Response.Redirect("../Default.aspx")
    End If
    Session("qid") = 0
End Sub

しかし、これはエラーになり、値にアクセスできません。

4

1 に答える 1

0

asp.net ページからメモリ内クラシック ASPSESSION にアクセスするための最も簡単なブリッジは次のようになります。

  • ASP 側: セッションを出力するための ASP ページ。たとえば、asp2netbridge.asp と呼びます。

    <%
    'Make sure it can be only called from local server '
    if (request.servervariables("LOCAL_ADDR") = request.servervariables("REMOTE_ADDR")) then
        if (Request.QueryString("sessVar") <> "") then
            response.write Session(Request.QueryString("sessVar"))
        end if
    end if
    %>
    
  • .net 側では、その ASP ページへのリモート呼び出し。:

    private static string GetAspSession(string sessionValue)
     {
        HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://yourdomain.com/asp2netbridge.asp?sessVar=" + sessionValue));
        _myRequest.ContentType = "text/html";
        _myRequest.Credentials = CredentialCache.DefaultCredentials;
        if (_myRequest.CookieContainer == null)
            _myRequest.CookieContainer = new CookieContainer();
        foreach (string cookieKey in HttpContext.Current.Request.Cookies.Keys)
        {
            ' it is absolutely necessary to pass the ASPSESSIONID cookie or you'll start a new session ! '
            if (cookieKey.StartsWith("ASPSESSIONID")) {
                HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieKey.ToString()];
                _myRequest.CookieContainer.Add(new Cookie(cookie.Name, cookie.Value, cookie.Path, string.IsNullOrEmpty(cookie.Domain)
                    ? HttpContext.Current.Request.Url.Host
                    : cookie.Domain));
            }
        }
        try
        {
            HttpWebResponse _myWebResponse = (HttpWebResponse)_myRequest.GetResponse();
    
            StreamReader sr = new StreamReader(_myWebResponse.GetResponseStream());
            return sr.ReadToEnd();
        }
        catch (WebException we)
        {
            return we.Message;
        }
    }
    
于 2012-10-24T14:16:02.260 に答える