开发者

Whats the namespace of Server.Transfer method?

I get a red underline under the Server Class:

Server.Transfer("~/PostEdit.aspx");

The mistake is:

Cannot access a non-static member of outer type 'System.Web.UI.Page' via nested type 'Answer开发者_JAVA百科Question.ThreadTable'

AnswerQuestion is the partial class and ThreadTable is a custom class that I made.


You are not inside the Page instance, so you don't have access to the Server property, which is a shortcut to the Server property in the HTTP context.

Use the static Current property to get the context of the current page:

HttpContext.Current.Server.Transfer("~/PostEdit.aspx");


HttpContext.Current.Handler
HttpContext.Current.Request.Server.Transfer

Context.Handler is an instance of an HttpContext.

HttpContext exposes the CURRENT instance for the request under the HttpContext.Current property, however the current context can also be passed in HTTPHandlers in the ProcessRequest method:

void ProcessRequest(HttpContext context)


The exception clearly says that you are accessing a non-static member in your class. It has nothing to do with Server.Transfer().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜