我目前正在尝试制作一个新的 Umbraco 文档,然后请求查询字符串 Rid 并运行我的代码(它将找到页面的 id 并希望正确显示)但我无法在它调用参考请求是一个asp.net 用户控件。我收到错误非静态字段、方法或属性“System.Web.Ui.UserControl.Request.get”需要对象引用
错误来自(请求未被识别)
Document rDoc = new Document(Convert.ToInt32(Request.QueryString["rid"]));
有任何想法吗?代码如下。如果您可以想到任何改进/此代码不起作用的任何原因,非常感谢您的解释,谢谢。
我的包括...
<%@Import Namespace="System.Net" %>
<%@Import Namespace="Newtonsoft.Json" %>
<%@Import Namespace="System.Web"%>
<%@Import Namespace="System.Web.Script.Serialization"%>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<%@Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.ComponentModel" %>
<%--Umbraco Includes--%>
<%@ Import Namespace="umbraco.cms.businesslogic" %>
<%@ Import Namespace="umbraco.cms.businesslogic.web" %>
<%@ Import Namespace="umbraco.cms.businesslogic.member" %>
static void Main(string[] args)
{
//Hashtable sqlDatatypeholder = new Hashtable();
Dictionary<string, string> sqlDatatypeholder = new Dictionary<string, string>();
DataTable tempTable = new DataTable();
string SheetToPopulate = "";
//Sql Connection
string _mySqlUrl = "sqlurl;";
string _mySqlQuery = "query;";
Document rDoc = new Document(Convert.ToInt32(Request.QueryString["rid"]));
SqlConnection conn = new SqlConnection(_mySqlUrl);
using (conn)
{
SqlCommand command = new SqlCommand(_mySqlQuery, conn);
conn.Open();
SqlDataReader reader = command.ExecuteReader();
DataTable schemaTable = reader.GetSchemaTable(); //stores datatypes from sql
tempTable.Load(reader); //stores data rows from sql
reader.Close();
//we need at least two date datatype fields for the sheet to be viewed in Gantt Chart view (smartsheet API rule), so everytime the date format is found, set to DATE
if (tempTable != null && tempTable.Rows.Count > 0)
{
foreach (DataRow row in schemaTable.Rows)
{
sqlDatatypeholder.Add(row["ColumnName"].ToString(), row["DataTypeName"].ToString());
}
}
else
{
Console.WriteLine("Connection Open - No rows found.");
Console.ReadLine();
}
}
SheetToPopulate = CreateSmartSheetFromDictionary(HashtableToDictionary(sqlDatatypeholder), tempTable);
// Console.WriteLine(SheetToPopulate);
PopulateSmartSheetRows(SheetToPopulate, tempTable);
// Console.WriteLine("Sheet Populated");
//Console.ReadLine();
}