webservice类可以继承asp.net page类吗

发布于 2024-10-10 11:13:08 字数 245 浏览 0 评论 0 原文

我有一个由两个 ASP.NET 项目组成的应用程序。我有一个继承 System.Web.UI.Page 的 BasePage ,并且该类具有我在所有页面中需要的一些核心逻辑(在 BasePage.cs 中实现) )。所以我的所有页面都继承了这个 BasePage.cs 。现在,除了普通的 Webservice 类之外,Webservice 是否可以继承相同的类 System.Web.Services.WebService

i have an application consisting of two asp.net projects. And i have have a BasePage which inherits System.Web.UI.Page and have the class some core logic which i require in all of my pages(Implemented in BasePage.cs). So all my pages inherit this BasePage.cs . Now can an Webservice inherit the same class apart from the normal webservice class System.Web.Services.WebService

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风轻花落早 2024-10-17 11:13:08

.NET 框架不支持多重继承。即使是这样,这种实施也很难被称为良好实践。

网页和 Web 服务页面调用的所有方法都应放入额外的类中。

Multiple inheritance is not supported in the .NET framework. And even if it was, this kind of implementation would hardly be called good practice.

All methods that are called by the web pages as well as the webservice pages should be put into extra classes.

甜尕妞 2024-10-17 11:13:08

任何可由网页和 Web 服务使用的逻辑都应位于可供两者使用的单独类中。此类逻辑不得依赖于 UI 的一部分。

将其放入静态类中,并让服务和页面都使用它。

Any logic that could be used both by a web page and by a web service should be in a separate class that can be used by both. Such logic must not depend on being part of a UI.

Put it into a static class and have both the service and the pages use it.

夜还是长夜 2024-10-17 11:13:08

视图和服务应该完全分开。服务不应该了解有关页面的任何信息。我想说如果可以的话你不应该这样做。

Views and services should be completely separate. Services should not know anything about pages. I would say you should not if you could.

ペ泪落弦音 2024-10-17 11:13:08

通常每个asp.net网页都会继承“System.Web.UI.Page”。
但在你的情况下,你有一个基类,该类继承“System.Web.UI.Page”,然后你将该基类用于所有 asp.net 网页,没有问题。
Web服务的基类是“System.Web.Services.WebService”,因此每当您使用Web服务时,您都应该继承该Web服务的类。您不能将基类 (BasePage.cs) 用于 Web 服务。

Normally every asp.net web page inherit "System.Web.UI.Page".
But in your case u have base class that class inherits "System.Web.UI.Page" then you use that base class for all asp.net web page no issues.
Web service's base class is "System.Web.Services.WebService" so whenever you use web service you should inherit this web service's class. You cannot use your base class(BasePage.cs) to your web service.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文