是否可以将会话从HttpWebResponse传输到浏览器?

时间:2016-10-25 23:14:35

标签: c# asp.net vb.net wcf session

我需要找到一些方法来按下一个顺序传输会话值:

WebApp1(WebForms) - > WCF - > WebApp2(WebForms / Browser)

原因是因为WCF服务必须在到达WebApp2 / Browser之前验证请求。

基本上我需要通过WCF获取HTML和会话,然后将它们传递给WebApp2中的Iframe

我有下一个代码:

WebApp1:

-Default.aspx

Public Class _Default
    Inherits Page

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

        Dim pUser As String = Request.QueryString("user")

        If Not String.IsNullOrEmpty(pUser) Then
            System.Web.HttpContext.Current.Session("user") = pUser
        End If

        Dim user As String = System.Web.HttpContext.Current.Session("user")

        If String.IsNullOrEmpty(user) Then
            Response.Write("sesion no iniciada")
        Else
            Dim a As String = "<a href='http://localhost:64852/About.aspx'>ir a otra pagina</a>"
            Response.Write(String.Format("{0} ha iniciado sesion {1} pagina 1", user, a))
        End If
    End Sub
End Class

-About.aspx

Public Class About
    Inherits Page

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

        Dim user As String = System.Web.HttpContext.Current.Session("user")

        If String.IsNullOrEmpty(user) Then
            Response.Write("sesion no iniciada")
        Else
            Dim a As String = "<a href='http://localhost:64852/Default.aspx'>ir a otra pagina</a>"
            Response.Write(String.Format("{0} ha iniciado sesion {1} pagina 2", user, a))
        End If
    End Sub
End Class

WCF:

-Service.svc(我将跳过界面的实用性)

Public Function abrirAplicacion(ByVal url As String, ByVal idPermiso As String, ByVal lenguaje As String) As System.IO.Stream Implements IServiceAAM.abrirAplicacion

    Dim r As String = url & "idPermiso=" & idPermiso & "&lang=" & lenguaje

    Return Utilities.Net.getHttpStream(r, "GET")
    'WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"
End Function

- 功能Utilities.Net.getHttpStream

Friend Shared Function getHttpStream(ByVal url As String, ByVal method As String, Optional ByVal request As String = "", Optional ByVal contentType As String = "") As System.IO.Stream

    url = "http://localhost:64852/Default.aspx?user=diego"
    Dim ba As Byte() = Encoding.Default.GetBytes(request)
    Dim lg As Integer = ba.Length
    Dim rq As HttpWebRequest = HttpWebRequest.Create(url)
    Dim cookies As New CookieContainer()

    With rq
        .ContentType = contentType
        .Method = method
        .Proxy = New WebProxy()
        .ContentLength = lg
        .CookieContainer = cookies
    End With

    If method <> "GET" Then
        Dim qs As Stream = rq.GetRequestStream()
        qs.Write(ba, 0, lg)
        qs.Flush()
        qs.Close()
    End If

    Dim qr As Stream

    Dim response As HttpWebResponse = rq.GetResponse()
    response.Cookies = cookies.GetCookies(rq.RequestUri)
    qr = response.GetResponseStream()

    Return qr
End Function

webapp2的:

Dim st As System.IO.Stream = oClient.abrirAplicacion(url, Server.UrlEncode(Encrypt(pIdPermiso)), lenguaje)
oClient.Close()

'IframeApp.Attributes("src") = url & "idPermiso=" & Server.UrlEncode(Encrypt(pIdPermiso)) & "&lang=" & lenguaje
'IframeApp.Attributes("height") = listSistema.First.tamano
Dim str As New System.IO.StreamReader(st)
IframeApp.Attributes("srcdoc") = str.ReadToEnd()

问题是返回纯文本(没有HTML)而没有任何会话

0 个答案:

没有答案