填写带有PageMethods的Asp.net页面以使用Ajax是一个好主意吗?

时间:2022-11-07 04:05:09

I'm still using webforms. At the moment I'm not planning to use MVS, despite this I need / I would like to use Ajax with jQuery but to do this I need to create a static [WebMethod] that acts as static, no session nor common things can be used, such getting things from DB using user data stored in session, at least easy way session[]=.

我还在使用webforms。目前我不打算使用MVS,尽管我需要/我想在jQuery中使用Ajax但是要做到这一点我需要创建一个静态的[WebMethod],它充当静态,没有会话,也没有常见的东西可以使用,比如使用存储在会话中的用户数据从DB获取东西,至少方便session [] =。

[WebMethod]
    public static void setAsRead(string rowid){}

(In the previous code I need to store in the page, as hidden field, the rowid of the table row which I need its data)

(在我之前的代码中我需要存储在页面中,作为隐藏字段,我需要其数据的表行的rowid)

So I wonder whether placing a lot of pagemethods to do so is "normal" or we have to avoid this approach. I personally think that it's ugly to see this because the page nature, it's a webform, a page, not a webservice stack.

所以我想知道放置很多页面方法是否“正常”或者我们必须避免这种方法。我个人认为看到这个是丑陋的,因为页面性质,它是一个webform,一个页面,而不是webservice堆栈。

So what do you think? Are there security issues? Do I have to avoid ajax with webforms and thinking to migrate to MVC?

所以你怎么看?有安全问题吗?我是否必须避免使用webforms并尝试迁移到MVC?

2 个解决方案

#1


1  

There's nothing wrong with PageMethods in classic WebForms in terms of security or performance. They are much better than the UpdatePanels as you have full control over the data that is being exchanged between the client and the server. The benefit of using PageMethods compared to raw IHttpHandler is that the framework will take care of the JSON serialization and the plumbing code for you.

在安全性或性能方面,传统WebForms中的PageMethods没有任何问题。它们比UpdatePanel好得多,因为您可以完全控制客户端和服务器之间交换的数据。与原始IHttpHandler相比,使用PageMethods的好处是框架将为您处理JSON序列化和管道代码。

So you could PageMethods until you decide to upgrade to ASP.NET MVC, ASP.NET Web API or ServiceStack where you could expose a REST API.

因此,您可以使用PageMethods,直到您决定升级到ASP.NET MVC,ASP.NET Web API或ServiceStack,您可以在其中公开REST API。

Do I have to avoid ajax with webforms and thinking to migrate to MVC?

我是否必须避免使用webforms并尝试迁移到MVC?

No, there's absolutely nothing wrong with doing AJAX in WebForms. People have been using it much before ASP.NET MVC ever existed. But if you are starting a new project you might really consider whether it wouldn't be worth the effort to migrate to ASP.NET MVC. This will very much depend on the specific requirements of your project, the existing codebase, ... Make sure you evaluate all possibilities really well before starting the migration process.

不,在WebForms中进行AJAX绝对没有错。在ASP.NET MVC曾经存在之前,人们一直在使用它。但是,如果您要开始一个新项目,您可能会考虑迁移到ASP.NET MVC是否值得。这在很大程度上取决于项目的具体要求,现有的代码库,......确保在开始迁移过程之前很好地评估所有可能性。

#2


1  

You don't need to move Asp.net MVC fo implementing ajax. You do still have options in Web Forms. Most of technologies are not Mvc spesific. You can use lots of technologies for backend.

您不需要移动Asp.net MVC来实现ajax。您仍然可以在Web窗体中使用选项。大多数技术都不是Mvc特有的。您可以将许多技术用于后端。

  • Http Handler : This is most basic one and most of the time my personel choice. You can use session by implementing IRequiresSessionState How to POST data to ASP.NET HttpHandler?

    Http Handler:这是最基本的一个,而且大部分时间都是我个人的选择。您可以通过实现IRequiresSessionState如何将数据POST到ASP.NET HttpHandler来使用会话?

  • Asp.net web-api This is the new shiny thing. Lots of godies. Support selfhosting etc.

    Asp.net web-api这是一个新的闪亮的东西。很多人。支持自托管等

  • Service stack If you are allowed to use 3rd party libraries. This one is definetly worth looking. Well documented, supported open source project.

    服务堆栈如果允许您使用第三方库。这个绝对值得一看。文档齐全,支持开源项目。

#1


1  

There's nothing wrong with PageMethods in classic WebForms in terms of security or performance. They are much better than the UpdatePanels as you have full control over the data that is being exchanged between the client and the server. The benefit of using PageMethods compared to raw IHttpHandler is that the framework will take care of the JSON serialization and the plumbing code for you.

在安全性或性能方面,传统WebForms中的PageMethods没有任何问题。它们比UpdatePanel好得多,因为您可以完全控制客户端和服务器之间交换的数据。与原始IHttpHandler相比,使用PageMethods的好处是框架将为您处理JSON序列化和管道代码。

So you could PageMethods until you decide to upgrade to ASP.NET MVC, ASP.NET Web API or ServiceStack where you could expose a REST API.

因此,您可以使用PageMethods,直到您决定升级到ASP.NET MVC,ASP.NET Web API或ServiceStack,您可以在其中公开REST API。

Do I have to avoid ajax with webforms and thinking to migrate to MVC?

我是否必须避免使用webforms并尝试迁移到MVC?

No, there's absolutely nothing wrong with doing AJAX in WebForms. People have been using it much before ASP.NET MVC ever existed. But if you are starting a new project you might really consider whether it wouldn't be worth the effort to migrate to ASP.NET MVC. This will very much depend on the specific requirements of your project, the existing codebase, ... Make sure you evaluate all possibilities really well before starting the migration process.

不,在WebForms中进行AJAX绝对没有错。在ASP.NET MVC曾经存在之前,人们一直在使用它。但是,如果您要开始一个新项目,您可能会考虑迁移到ASP.NET MVC是否值得。这在很大程度上取决于项目的具体要求,现有的代码库,......确保在开始迁移过程之前很好地评估所有可能性。

#2


1  

You don't need to move Asp.net MVC fo implementing ajax. You do still have options in Web Forms. Most of technologies are not Mvc spesific. You can use lots of technologies for backend.

您不需要移动Asp.net MVC来实现ajax。您仍然可以在Web窗体中使用选项。大多数技术都不是Mvc特有的。您可以将许多技术用于后端。

  • Http Handler : This is most basic one and most of the time my personel choice. You can use session by implementing IRequiresSessionState How to POST data to ASP.NET HttpHandler?

    Http Handler:这是最基本的一个,而且大部分时间都是我个人的选择。您可以通过实现IRequiresSessionState如何将数据POST到ASP.NET HttpHandler来使用会话?

  • Asp.net web-api This is the new shiny thing. Lots of godies. Support selfhosting etc.

    Asp.net web-api这是一个新的闪亮的东西。很多人。支持自托管等

  • Service stack If you are allowed to use 3rd party libraries. This one is definetly worth looking. Well documented, supported open source project.

    服务堆栈如果允许您使用第三方库。这个绝对值得一看。文档齐全,支持开源项目。