So I have two functions and I'm getting an interesting problem. Essentially I'm aiming to make my code more portable in an easily includeable cs file.
Here's said cs file:
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();
}
}
}
Here is the page that is referencing it:
<% @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>
The error I'm getting is the one listed above, namely:
Compiler Error Message: CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Server.get'
On the following line:
Line 5: string path = Server.MapPath("./" + filename);