visual-studio 如何在 Visual Studio 中编译和运行 ashx 文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1336910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:55:30  来源:igfitidea点击:

How do I compile and run an ashx file in visual studio?

c#asp.netvisual-studio

提问by Johannes Hoff

I have

我有

  • an ashx file,
  • Visual Studio 10,
  • no knowledge at all about C# ASP.NET
  • 一个 ashx 文件,
  • 视觉工作室 10,
  • 对 C# ASP.NET 一无所知

What is the proper way to compile and run this?

编译和运行它的正确方法是什么?

Context

语境

The ashx file in question can be found in this zip, and is a demo application for a Tetris AI competition. It is a very enticing idea even if it depends a great deal on luck, and I thought I might use the occasion to learn a new language.

可以在此 zip 中找到有问题的 ashx 文件,它是俄罗斯方块 AI 竞赛的演示应用程序。这是一个非常诱人的想法,即使它在很大程度上取决于运气,我想我可能会利用这个机会学习一门新语言。

回答by John Rasch

An ashxfile is a just a generic HTTP handler, so the easiest way to get this working is to create a new Web Site in the File menu, and just add the Handler.ashxfile to the website root directory.

一个ashx文件是只是一个普通的HTTP处理程序,所以得到这个工作的最简单的方法是创建在文件菜单中一个新的网站,只是添加的Handler.ashx文件到网站根目录。

Then, just run the site (F5) and browse to "YourSite/Handler.ashx".

然后,只需运行站点 (F5) 并浏览到“ YourSite/Handler.ashx”。

回答by dnord

An ASHX file is like an ASPX file, but it's a handler. That means it doesn't respond back with HTML by default, and can therefore "handle" otherwise unhandled file types, but it's not necessarily tied to that meaning. In this case, you'll only be presenting the response

ASHX 文件类似于 ASPX 文件,但它是一个处理程序。这意味着默认情况下它不会以 HTML 响应,因此可以“处理”其他未处理的文件类型,但它不一定与该含义相关联。在这种情况下,您将只提供响应

position=8&degrees=180

...to a posted board and piece. So you don't need HTML, so you want an ASHX.

...贴到一块板子上。所以你不需要 HTML,所以你想要一个 ASHX。

You can make .ashx files the startup page in your project, just the same as .aspx pages. If I were writing a HelloUser.ashx page, I might set it as the start page, with some parameters passed in as querystrings or something.

您可以将 .ashx 文件作为项目中的启动页面,就像 .aspx 页面一样。如果我正在编写一个 HelloUser.ashx 页面,我可能会将其设置为起始页面,并将一些参数作为查询字符串或其他内容传入。

You're probably going to want a test harness that posts a board / piece to your service, and that could be any kind of project. Command line program, website, test class run through NUnit, whatever. There's a lot of logic to keep track of beyond the "player" logic.

您可能需要一个测试工具来向您的服务发布板/件,这可以是任何类型的项目。命令行程序、网站、测试类通过 NUnit 运行,等等。除了“玩家”逻辑之外,还有很多逻辑需要跟踪。

If you need a more detailed answer than that, SO might not be the place for this question. But I wish you all kinds of luck with this - it's an interesting problem.

如果您需要比这更详细的答案,SO 可能不是这个问题的地方。但我祝你一切顺利 - 这是一个有趣的问题。

回答by Josh Stodola

You need to deploy it to an IIS server that has the proper .NET framework installed and that should be it.

您需要将其部署到安装了适当 .NET 框架的 IIS 服务器上,应该就是这样。

If you are trying to get it working locally, create a web site project in visual studio, go to "add existing items" in solution explorer, and locate your ashx. Then click the play button (or press F5) to compile and run it.

如果您试图让它在本地工作,请在 Visual Studio 中创建一个网站项目,转到解决方案资源管理器中的“添加现有项目”,然后找到您的 ashx.xml 文件。然后单击播放按钮(或按 F5)编译并运行它。

Good luck!

祝你好运!

回答by apiguy

You're missing an some form (an ASPX file maybe) that goes with this handler. It looks like this thing probably handles some AJAX request from another page.

您缺少与此处理程序一起使用的某种形式(可能是 ASPX 文件)。看起来这个东西可能会处理来自另一个页面的一些 AJAX 请求。

It's expecting 2 pieces of data with the request as well:

它还期望带有请求的 2 条数据:

string board = context.Request.Form["board"];
string piece = context.Request["piece"];

You could reverse engineer the form that this is for, but it will probably take some time to get that board array right.

您可以逆向工程这是用于的形式,但可能需要一些时间才能使该电路板阵列正确。