Для нестатического поля, метода или свойства System.Web.UI.Page.Server.get требуется ссылка на объект.

Итак, у меня есть две функции, и я получаю интересную задачу. По сути, я стремлюсь сделать свой код более переносимым в легко подключаемом файле cs.

Вот указанный файл cs:

namespace basicFunctions {
public partial class phpPort : System.Web.UI.Page {
    public static string includer(string filename) {
        string path = Server.MapPath("./" + filename);
        string content = System.IO.File.ReadAllText(path);
        return content;
    }
    public void returnError() {
        Response.Write("<h2>An error has occurred!</h2>");
        Response.Write("<p>You have followed an incorrect link. Please double check and try again.</p>");
        Response.Write(includer("footer.html"));
        Response.End();
    }
}
}

Вот страница, которая ссылается на него:

<% @Page Language="C#" Debug="true" Inherits="basicFunctions.phpPort" CodeFile="basicfunctions.cs" %>
<% @Import Namespace="System.Web.Configuration" %>

<script language="C#" runat="server">
void Page_Load(object sender,EventArgs e) {
    Response.Write(includer("header.html"));
    //irrelevant code
    if ('stuff happens') {
        returnError();
    }
    Response.Write(includer("footer.html"));
}
</script>

Ошибка, которую я получаю, указана выше, а именно:

Сообщение об ошибке компилятора: CS0120: ссылка на объект требуется для нестатического поля, метода или свойства 'System.Web.UI.Page.Server.get'

В следующей строке:

Строка 5: string path = Server.MapPath("./" + имя файла);

9
задан Oded 8 May 2012 в 19:36
поделиться