Asp.net 在网页上使用代码隐藏中的函数
免责声明:我对ASP.NET还很陌生,所以我会边走边想办法 我试图在网页本身的代码隐藏页面中输出函数的结果 例如: 代码隐藏:Asp.net 在网页上使用代码隐藏中的函数,asp.net,code-behind,Asp.net,Code Behind,免责声明:我对ASP.NET还很陌生,所以我会边走边想办法 我试图在网页本身的代码隐藏页面中输出函数的结果 例如: 代码隐藏: public string POSTResult(string e) { ... return TheResult; } ASPX页面: Output is: <%=POSTResult("argument")%> 正在传递的参数示例,API密钥已编辑: code=[redacted]&client_id=[redacted]&clien
public string POSTResult(string e) { ... return TheResult; }
ASPX页面:
Output is: <%=POSTResult("argument")%>
正在传递的参数示例,API密钥已编辑:
code=[redacted]&client_id=[redacted]&client_secret=[redacted]&redirect_uri=http://localhost:60284/login.aspx&grant_type=authorization_code
ETA2:
我不知道这是否相关,但我的代码隐藏页面和我的网页似乎根本没有相互通信。例如,我无法通过代码隐藏页面中的ID访问div以更改其内容。我已编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。你能把你所有的代码都贴在后面吗(
login.aspx.cs
)?约翰-我不知道。谢谢你修理它!如果我使用CodeBehind=“~/login.aspx.cs”它可以工作,如果我省略了~/它就不能工作。这是一个设置还是我需要更新的东西?这是一个网站还是一个web应用程序?
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;
}
}
}
code=[redacted]&client_id=[redacted]&client_secret=[redacted]&redirect_uri=http://localhost:60284/login.aspx&grant_type=authorization_code