1
votes

We have a number of classic ASP websites using a VB6 DLL (COM) object for their functionality in the standard way. The DLL is regsvr32'd and the pages use Server.CreateObject to create an instance of the necessary object in the DLL, which in turn triggers the OnStartPage function of the object being created, passing in the ScriptingContext which we then use to get Request (querystring, form) information, read/update session information and read/write cookie information (etc). For clarification, the way you update/store a cookie value using ScriptingContext is

objSC.Response.Cookies(Key) = Value

In preperation of doing a complete .Net overhaul on the code base (and as a first step), we ran the code through the .Net 2008 VB upgrade tool, which makes a few minor code changes, sets up references to interop libraries (for ADODB, ASPTypeLibrary, CDO, etc) and adds the necessary attributes to allow the .Net object to be exposed to COM, and after a few tweaks here and there guided by comments (todos) left by the upgrade tool, the code is compilable except for anything that tried to update/store a cookie using the above code as now, through the ASPTypeLibrary (Interop), the Response.Cookies collection is readonly (with no obvious way to write a cookie now).

If I comment out the offending line of code, the code compiles, and all I need to do is register this new .Net DLL (and it's interop DLLs) in the GAC, use regasm to register it through COM and the classic ASP sites continue working as if nothing happened (except for writing cookies), using Server.CreateObject to create what it thinks is a COM object, triggering the call to OnStartPage, passing in the ScriptingContext.

So although the code base is "upgraded" to .Net it is using a lot of interop libraries to continues working as before, including using the ASPTypeLibrary.ScriptingContext object, as this is what the classic ASP pipeline exposes.

Does anyone know how to write/store a cookie in this scenario?

1
You are upgrading what is ASP/VBScript to ASP.NET/VB.NET? But if that were true SLaks now deleted answer would be true. So what are you doing exactly? What bit is being "upgraded"? Are you upgrading the DLL to a .NET code base and using that in ASP classic or something else?AnthonyWJones
I've rewritten for clarification.John Freebs

1 Answers

3
votes

Need to convert cookie item to IWriteCookie interface. Then it will be writable.

Imports ASPTypeLibrary
Public Class Test
    Private oContext As ASPTypeLibrary.ScriptingContext
    Private oResponse As ASPTypeLibrary.Response
    Public Sub OnStartPage(e As ScriptingContext)
        oContext = e
        oResponse = oContext.Response
        With CType(oResponse.Cookies("fromdotnet"), IWriteCookie)
            .Item = String.Format("hello from .Net : {0}", Date.UtcNow())
            '.Domain = ""
            '.Path = "/"
            '.Secure = False
        End With
    End Sub
End Class

You may want to check out other interfaces such as IReadCookie, IStringList, IRequestDictionary etc.

With note that:

Full trust for the immediate caller. This member cannot be used by partially trusted code.

there is another option : ContextUtil.GetNamedProperty Method

System.EnterpriseServices.ContextUtil.GetNamedProperty("Response").Cookies("fromdotnet") = "hello"