ASP.Net:在项目中创建处理程序

发布于 2024-09-12 00:47:05 字数 186 浏览 2 评论 0原文

抱歉,如果这是一个愚蠢的问题。我想在我的项目中创建一个 HTTP 处理程序。为此,我创建了一个新类,并尝试实现 IHttpHandler。

每次执行此操作时,我都会收到错误“预期语句结束”。

我知道通常您可以创建一个新的类库并创建一个类来实现处理程序。但为什么在现有的 Web 项目中无法做到这一点呢?

WT

Sorry if this is a stupid question. I want to create an HTTP handler within my project. To do this, I created a new class, and tried to implement IHttpHandler.

Each time I do this, I get the error 'End of statement expected'.

I know that normally you can create a new class library and create a class to implement a handler. But why is it not possible to do this in an existing web project?

WT

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

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

发布评论

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

评论(2

诺曦 2024-09-19 00:47:05

创建一个名为 ashx 或通用处理程序的新对象。从那里您可以输入服务器端代码并​​输出您想要给出的确切结果。老实说,虽然我会使用 WCF,但它要容易得多,而且您可以以您喜欢的任何数据类型吐出数据。

Create a new object called an ashx or Generic Handler. From there you can put in server side code and output the exact result you would like to dish out. Honestly though I would use WCF though, its a lot easier and you can spit out the data in any data type you like.

星星的軌跡 2024-09-19 00:47:05

尽管将其放入 Web 项目中不是最佳实践,但您是否在 web.config 中正确引用了它,以便它知道在 App_Code 文件夹中查找?

<httpHandlers>
    <add verb="*" path="*.yourextention" type="YourHandler, App_Code"/>
</httpHandlers>

Even though its not a best practice to put it in the web project, are you referencing it in the web.config correctly, so it knows to look in the App_Code folder?

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