I have
an ashx file,
Visual Studio 10,
no knowledge at all about 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.
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.
Then, just run the site (F5) and browse to "YourSite/Handler.ashx".
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
position=8°rees=180
...to a posted board and piece. So you don't need HTML, so you want an 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.
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.
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.
You need to deploy it to an IIS server that has the proper .NET framework installed and that should be it.
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.
Good luck!
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.
It's expecting 2 pieces of data with the request as well:
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.
Related
So I imported this aspx page done by a former dev who worked for the company I'm in now. I found that the aspx page left by him doesn't have a codebehind file so I assumed this wasn't the source code. I can't find the source so I added a code file and try to work it out on my own. But my main concern is this: clients can't access the code behind, right? Is a manually added code file subject to the same protection?
The codebehind file is there as a place to put your server side code. However it's technically not necessary to have one since you can put the code in the aspx file using c# script tags. It's however recommended to put it in the codebehind file for better separation between markup and code.
It does not matter if you add it yourself or if Visual Studio adds it for you. It does not change anything in terms of access. In all events it executes on the server.
If your server is properly configured to run ASP.NET applications - which I believe it is - then IIS will not serve .cs files to a client. These will normally be accessible only through FTP. Try it yourself, by browsing to any .cs file in your application :)
Also notice that what you get when you browse to an .aspx file is not the very same code you'd see in Visual Studio, but the result of that being processed. IIS will serve the resulting HTML. So even if you have server side code in the ASPX file, that won't be visible to an end user browsing through your application.
Sounds like a web application project; in this case, the code is in the code-behind file as #TGH mentioned, and the code would be in the DLL compiled for the web application. Therefore, the only way to get that code is use a tool like Telerik JustDecompile, and decompile that DLL to grab the source code for EVERY file in the project. It would be much better to have the source, as these decompile tools do not include everything in that code-behind file.
So this is going to bed a dumb question because I understand there is a simple solution, I just cannot figure it out....
At the moment I am running my MVC 5 project in visual studio 2013... Normally when I want to debug it I will just click run and the website will appear in the browser of my choice...
I just recently published it to my companys web server and now I am having all kinds of issues...
The website is just 15 buttons on the Home/Index page and I want to be able to click on the buttons and still run them on my localhost side and when I publish them, still have them find the right path..
Here is an example because I am not very good at explaining things...
I run it in visual studio my url is:
http://localhost:54641/Home/Index
I run my published site on the webserver my url is:
http://webserver/racklabels/dakkota/Home/Index
I understand this part, and in either case both of them work but when it comes to clicking on a button, or images.. the pathing is all weird and I dont understand it.
In visual studio I click my first button and my url becomes:
http://localhost:54641/RecieveTruck/AddFor
On my webserver I click it and it turns to:
http://webserver/RecieveTruck/AddFor
but gives me the 404 error because it is not the correct route ( which should be..
http://webserver/racklabels/dakkota/RecieveTruck/AddFor
)
This is how I have my button setup in my View (Index.cshtml) and I am wondering if this is what is causing the probelm (I am thinking that I may have to do it a different way other than using onclick)
<input type="button" name="receive" value="Receive Truck" style="cursor: pointer;" class="bodyText"
onmouseover="this.style.color='orangered';" onmouseout="this.style.color='black';"
onclick="document.location.href='/RecieveTruck/AddForm';">
Basically I would like for this to work regardless of how many folders I am deep after I publish it and when I click run in visual studio (so I can debug/test and just republish to the webserver when I want to update)
I have tried many different ways of sending the path... like '~/RecieveTruck/AddForm' (which just adds the ~ to the address) and '../RecieveTruck/AddForm' and just 'RecieveTruck/AddForm' but none of them find the actual root of where the project lives and just adds this to it...
Can anybody help me?
You can use
#Url.Content("~/Home/Index")
but this completely misses out the benefit of mvc routing.
if you want to generate urls for controller actions, it's much better to use
#Url.Action("Index","Home")
...so now if you set up some snappy routing rule, the url in provided by .Action will adjust automagically (such as omitting url parts that have default values in your routing rules).
You need to add "~" to the front of the url document.location.href='~/RecieveTruck/AddForm'
or if that does not work use document.location.href='#Url.Content("~/RecieveTruck/AddForm")'
I'm new to ASP.NET, and would like an understanding of when/where to use WSP vs WAP.
I will make a rather simple business website, with 6-7 pages, where one page will open a registration/login form where the user can see various personal data and reports, pulled from a database.
Would this suggest the use of a combination of WSP and WAP, where for example the login window is part of the WSP, and a successful login opens a WAP in a frame or in a new browser window/tab?
mmhh you are confused with the notion of web application and web site.
You cannot make one page in one way and another the other way, because WAP and WSP are type of project. So it is at the beginning of your project in visual studio to decide which one to use.
Basically, WSP is leaving the compilation of your code to IIS, and so you are working only with files. Using WAP, your project behaves like in a normal application, Visual studio will then compile your code to create different dll. You will then have only to move to your production environment the page aspx and the dlls, whereas with WSP, you would also include aspx.cs.
this link will tell you everything you might want to know
hope it helped,
I am occasionally getting "Application compilation is starting." event in my Event Log and I can't identify what's causing it. I think I may try this - http://blogs.msdn.com/b/tess/archive/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing.aspx - but before I do that I was curious if I can identify the problem without starting to mess with something unknown.
I have used <%= %> and <%# %> tags throughout the app so I am wondering if this is what's causing the problems. On couple spots I have embedded C# code (using ) so that may add to it?
Precompiling the app is also valid choice for me, I just don't want to end in position in which I need execute precompilation command on the server every time I upload some changes to the server. Currently on my dev machine I've followed advices from this link - http://mikehadlow.blogspot.com/2008/05/compiling-aspx-templates-using.html - and it does awesome job as it allows me to identify errors in C# code in .aspx pages during build in Visual Studio. However, I presume precompilation results are not stored in my website directory (and won't be published when I use Publish option).
Ideally, I want to stay in position I am with default Web Application model with addition of automatically running compilation as soon as I upload changed .aspx or .ascx over FTP (not waiting for user's http request). Am I asking too much, or is this possible to setup?
From my research it seems it can.
Because nobody responded I'll accept this as answer.
We all know that it is possible to "open" a Word document (or file from any arbitrary application) by clicking on a website link and then clicking the Open button.
I also know that, if I want to upload an application document to a web server, I must first save the document to my computer, and then go to an upload page, click a file/open button, find my saved file and upload it.
But is it possible to save a document to a website location or Url, effectively skipping the first save step and uploading the file to the web server through the Save dialog of the application, directly?
How would this be done in ASP.NET MVC?
It really depends on how complex you want to make it. This is pretty much what "web folders" offered (via WebDAV), but in general it creates more problems than it will ever fix. I don't recommend this approach.
Your best bet to make this simple is a dedicated client app - perhaps (although this is a dubious example) how Office talks to sharepoint. In a simpler example, you could create a silverlight out-of-browser application that saved via a web-service to a site using WCF or similar.
I think there is some creedence in what #Marc says. Personally I'd probably map a drive to the web site in question, if that's possible, and have a folder to upload to.
Then I'd have .Net check changes to the folder and take those files and import them into the repository, whatever that may be.
It's still an imperfect solution and I'm not sure there is a correct solution as yet.
I guess you could always write, and I can't believe I'm writing this, macros to save to the ftp location.
I'd guess you have a few choices, in no particular order:
Web service that the application can reference and upload through.
REST service (WCF or otherwise) that the application can POST to.
HttpHandler or MVC controller action that the application can POST to.
WebDAV directly to the server.
Number 3 sounds like it's closest to what you were looking for ("How would this be done in ASP.NET MVC?"). Scott Hanselman has a good article on handling file uploads in MVC on his blog.
When you implement the client, there's a little bit of a trick to that, too, since you can't just POST like usual; you have to post in multipart/form-data format. I posted a blog entry with some sample code on how to do that.