简体   繁体   English

C#代码中的Server.Transfer。 服务器在当前上下文中不存在

[英]Server.Transfer in C# code. Server does not exist in current context

I'm making a method that will be called from a webpage, which uses Server.Transfer to terminates execution of the current page and starts execution of a new page. 我正在制作一种将从网页调用的方法,该方法使用Server.Transfer终止当前页面的执行并开始执行新页面。

However, since the method I'm making is not an aspx page, Service Studio complains about the Server instance not existing in current context. 但是,由于我使用的方法不是aspx页面,因此Service Studio抱怨当前上下文中不存在该Server实例。

How can I circumvent this? 我该如何规避?

Use HttpContext.Current ( System.Web.HttpContext class defined in System.Web ) 使用HttpContext.CurrentSystem.Web.HttpContext class defined in System.Web

Even if you are developing class library for web application you can reference and use it. 即使您正在开发Web应用程序的类库,也可以引用和使用它。

you would need HttpContext.Current.Server but you may find other useful data there too. 您将需要HttpContext.Current.Server但在那里您可能还会找到其他有用的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM