DNN: HttpContext.Current.Session not Working

I’m not an expert in .NET programming and I’m trying to solve this problem but no success.

We decided to revamp our old website and part of it is to switch theme. But we have a function from old that we can’t move to the new theme.

Our old website has a function that will get user’s session code, so that if they move to our affiliate website via url, they will be automatically logged in.

This is the code from our old theme…

OLD THEME CODE

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="/Home.ascx.cs" Inherits="Mandeeps.DNN.Skins.Tucson.Tucson" %>
<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<script type="text/javascript">
var onetimeurl = "<%#HttpContext.Current.Session["OneTimeURL"]%>";
$(document).ready(function() {
    $('.financials_link').attr("href", "https://sub.domain.com?authToken=" + onetimeurl);
    $('.financials_link').attr("target", "_blank");
    var service = $.ServicesFramework(-1);
    $.ajax({
        type: "GET",
        url: service.getServiceRoot("WebAuthModule") + "webauth/getauthtoken",
        beforeSend: service.setModuleHeaders,
        dataType: "json"
    }).done(function(a) {
        a && $(".financials_link").attr("href", "https://sub.domain.com?authToken=" + a)
    });
});
</script>

It’s working great. But when moved the code to the new theme, the code is not showing up and its breaking the page’s layout. And I’m getting this error.

Line 20: Error BC30516: Overload resolution failed because no accessible 'ToString' accepts this number of arguments.

NEW THEME CODE

<%@ Control Language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.UI.Skins.Skin" %>
<script type="text/javascript">
 var onetimeurl = "<%#HttpContext.Current.Session["OneTimeURL"]%>"; <!--LINE 20-->
$(document).ready(function() {
    $('.financials_link').attr("href", "https://sub.domain.com?authToken=" + onetimeurl);
    $('.financials_link').attr("target", "_blank");
    var service = $.ServicesFramework(-1);
    $.ajax({
        type: "GET",
        url: service.getServiceRoot("WebAuthModule") + "webauth/getauthtoken",
        beforeSend: service.setModuleHeaders,
        dataType: "json"
    }).done(function(a) {
        a && $(".financials_link").attr("href", "https://sub.domain.com?authToken=" + a)
    });
});
</script>

Noticed on the first line, I added the control codes because that is the only thing I think is different from each other. The rest are pretty much the same.

What I’ve done so far is I decompiled the Home.ascx (.dll) and looked for the OneTimeURL, but I wasn’t able to find it.

I wish you guys can spot the problem so I can fix this.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It seems odd to me that you are saying the old one is C# and the new one is VB??

But given what I see above, try this, just change the square brackets to parens, so the new line 20 is:

var onetimeurl = "<%#HttpContext.Current.Session("OneTimeURL") %>";

If that doesn’t work, then add try adding this function at the bottom.

<script runat="server">
Public Function GetSession() As String
  Return HttpContext.Current.Session("OneTimeURL")
End Function
</script>

And then line 20 would need to be:

var onetimeurl = "<%#GetSession() %>";


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x