0

I am designing a website in ASP.NET, and I am integrating the Steam API into it. I am using DotNetOpenAuth for the authentication. I am confused as to how I am to access and display the variable responseURI (Line 22). Whenever I try to display the variable on the webpage using this:

<p><%=responseURI%></p>

I get a message stating:

The name 'responseURI' does not exist in the current context.

Here is my C#

using DotNetOpenAuth.OpenId.RelyingParty;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class loginPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var openid = new OpenIdRelyingParty();
        var response = openid.GetResponse();

        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    // do success
                    var responseURI = response.ClaimedIdentifier.ToString();
                    break;

                case AuthenticationStatus.Canceled:
                case AuthenticationStatus.Failed:
                    // do fail
                    break;
            }
        }
        else
        {
            using (OpenIdRelyingParty openidd = new OpenIdRelyingParty())
            {
                IAuthenticationRequest request = openidd.CreateRequest("http://steamcommunity.com/openid");
                request.RedirectToProvider();
            }
        }
    }
}
1

1 Answer 1

4

Because it doesn't exist in the page's context, only in the context of that switch case. The Page is the class, just make it a class-level value. (I believe the visibility needs to be at least protected, since the displayed page "inherits" from the code-behind page.)

protected string ResponseURI { get; set; }

That would be placed at the class-level, like any other property in C#. For example:

protected string ResponseURI { get; set; }

protected void Page_Load(object sender, EventArgs e)
{
    //...
}

Then set that in your code instead:

this.ResponseURI = response.ClaimedIdentifier.ToString();

And display it on the page:

<%=ResponseURI%>
Sign up to request clarification or add additional context in comments.

9 Comments

@SlothGod: In your code-behind, of course. The property is a class-level member, and the other two lines replace your current attempted usages of your local responseURI variable.
I mean where in my code behind? What line? Sorry if I am seeming rude at all, I don't mean to, I just read back my comments and it looks worse than I meant to say it
@SlothGod: Well, since this is replacing the responseURI variable, you'd generally start on the line which declares and uses the responseURI variable.
Now I'm getting the same error message as before, but now for a lot of other variables.
@SlothGod: Answer updated. Not to sound condescending or anything, but if you're not familiar with the basic structure of C# code then what you're trying to do is a bit advanced for you. You should really be started with some introductory tutorials first.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.