简体   繁体   English

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

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

I have 我有

  • an ashx file, 一个ashx文件,
  • Visual Studio 10, Visual Studio 10,
  • no knowledge at all about C# ASP.NET 根本不了解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 . 有问题的ashx文件可以在这个zip中找到,并且是Tetris AI竞赛的演示应用程序。 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. 这是一个非常诱人的想法,即使它在很大程度上取决于运气,我想我可以借此机会学习一门新语言。

An ashx file 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.ashx file to the website root directory. ashx文件只是一个通用的HTTP处理程序,因此最简单的方法是在“文件”菜单中创建一个新的Web站点,然后将Handler.ashx文件添加到网站根目录。

Then, just run the site (F5) and browse to " YourSite/Handler.ashx ". 然后,只需运行该站点(F5)并浏览到“ YourSite/Handler.ashx ”。

An ASHX file is like an ASPX file, but it's a handler. ASHX文件就像一个ASPX文件,但它是一个处理程序。 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. 这意味着默认情况下它不会响应HTML,因此可以“处理”其他未处理的文件类型,但它不一定与该含义相关联。 In this case, you'll only be presenting the response 在这种情况下,您只会展示回复

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. 您可以将.ashx文件作为项目中的启动页面,与.aspx页面相同。 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. 如果我正在编写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. 命令行程序,网站,测试类通过NUnit运行,无论如何。 There's a lot of logic to keep track of beyond the "player" logic. 除了“玩家”逻辑之外,还有许多逻辑可以追踪。

If you need a more detailed answer than that, SO might not be the place for this question. 如果您需要更详细的答案,那么SO可能不适合这个问题。 But I wish you all kinds of luck with this - it's an interesting problem. 但是我祝你们好运 - 这是一个有趣的问题。

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. 如果您尝试在本地工作,请在visual studio中创建一个网站项目,转到解决方案资源管理器中的“添加现有项目”,然后找到您的ashx。 Then click the play button (or press F5) to compile and run it. 然后单击播放按钮(或按F5)编译并运行它。

Good luck! 祝好运!

You're missing an some form (an ASPX file maybe) that goes with this handler. 你错过了一个与这个处理程序一起使用的表格(可能是一个ASPX文件)。 It looks like this thing probably handles some AJAX request from another page. 看起来这个东西可能会处理来自另一个页面的一些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. 您可以对此形式进行反向工程,但可能需要一些时间才能使该板阵列正确。

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

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