免责声明:我对ASP.NET很陌生,所以我随身携带它。
我正在尝试在网页本身的代码后面输出函数的结果。
示例:
代码背后:
public string POSTResult(string e) { ... return TheResult; }
ASPX页面:
Output is: <%=POSTResult("argument")%>
但是,加载页面错误,说“当前上下文中不存在名称'POSTResult'。”
我显然正在做一些关于我如何从ASPX页面进入代码隐藏的代码。我的ASPX页面位于顶部:
<%@ Page Title="" Language="C#" MasterPageFile="~/master/default.Master" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Bitfork.login" %>
列出的CodeBehind值是页面背后代码的名称。
ETA:
我的代码内容(login.aspx.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
namespace Bitfork.master
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string POSTResult(string e)
{
// variables to store parameter values
string url = "https://accounts.google.com/o/oauth2/token";
// creates the post data for the POST request
string postData = (e);
// create the POST request
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = postData.Length;
// POST the data
using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
{
requestWriter2.Write(postData);
}
// This actually does the request and gets the response back
HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();
string responseData = string.Empty;
using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
{
// dumps the HTML from the response into a string variable
responseData = responseReader.ReadToEnd();
}
return responseData;
}
}
}
传递参数的示例,使用API密钥编辑:
code=[redacted]&client_id=[redacted]&client_secret=[redacted]&redirect_uri=http://localhost:60284/login.aspx&grant_type=authorization_code
ETA2:
我不知道它是否相关,但看起来我的代码页面和我的网页根本没有相互通信。例如,我无法在我的代码隐藏页面中按ID访问DIV以更改其内容。