Reputation: 376
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();
}
}
}
}
Upvotes: 0
Views: 1943
Reputation: 219097
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%>
Upvotes: 4