As the title of the topic may suggest, I have a PHP script setup on my server that, when called upon, is spitting data back to the user by echoing it back onto the page. I am then using HttpWebRequest to read the data that was put onto the page by the PHP script. While this data is encrypted, I would like for it to not appear on the page at all. I figured there must be a better way to go about doing this.
If I have been unclear thus far regarding my intentions, I am looking for some way to return data from a PHP page, so that I can retrieve it using HTTPWebResponse. Perhaps, for example, I could POST the data? I'm quite new to PHP so I figured I'd ask the experts here.
Thank you for any help,
Evan
I think the best safe way is use RSA Encrypt in .NET. You can read and download project at here
You can't post the data to the application, unless the application was a webserver. There's not really much other way to do it than the way you are doing it already.
Well, Since you're using http, it's logical to echo the data in the request stream within your php script. This way the other side (your .NET code can pick it up). If this is a problem for you, there are a few workarounds.
a: call your PHP script from .NET with a callback url refering back to your .NET application. Now the PHP script can actually post data back to the callback url. This however requires your .NET app to host a webservice.
b: you can put certain data in your php script without actually putting it in the request body by making it a mime header field like:
header('X-MyProject-Name: ' .$name);
header('X-MyProject-Age: ' .$age);
header('X-MyProject-Address: ' base64_encode(json_encode($complexAddressObject)));
Hope this helps
Related
We're looking to set up a WebHook receiver in our asp.net application. We've already got a simple aspx document that is able to receive and process the WebHook on the server side when it's received.
While this works, we're pretty sure an aspx file that just grabs and processes whatever is sent to it isn't the best option security-wise. Also, it doesn't need to serve a aspx document back so we figure that's probably a waste of resources.
In the process of looking for alternatives, we've found the following:
The Microsoft.AspNet.WebHooks.Receivers NuGet Package - After some research we discovered that the documentation for this isn't great and every once in a while you'll see mentions of Azure which we don't use. Makes it even more confusing.
Using a handler to do the processing instead of an aspx page - We thought maybe a handler would be able to run just on the server side when a POST is received so we don't need to send a whole aspx page back. This doesn't appear to be a common use for these though.
Any search tips or things we may be missing?
I am new to ASP, and have jumped right in and started a new MVC 4 project.
I am using the standard template and am trying to edit the login page. The problem I am trying to solve is this:
If you open Fiddler and login you can see the user name and password in plain text. What I would like to do would be to use a C# function I have created in a helpers file BEFORE the post is submitted, for example on a button click event, is this possible?
If so can someone point me in the direction of a tutorial/ example please as this has baffled me for a few days now!
Thanks again for your help
Don't reinvent the wheel. Use https instead so that data does not travel as plain text.
You can't run a C# function before the postback, how would you accomplish that? C# code runs server-side, but you post the form from the client-side. You can't apply a C# method on something you haven't shown it yet.
You have basically two options:
1.) use javascript to somehow alter the data before sending it to the server
2.) use SSL to protect the channel
The problem with the first option is, that ANYONE who sees the form can see your javascript code as well. In other words, no matter how strong protection you come up with, the attacker sees the algorithm, so he can decode the data very easily... Probably the most reliable option is the second one - SSL. It isn't 100%, but at least it's much harder to penetrate...
If you want to encrypt the data before the form is submitted you can only rely on client side code - javascript. This is in no way the optimal solution, as already pointed out by others, you should use https.
I am using the Nancy Web Framework in my C# Console Application to basically create a Web Administration panel for my software. I have opted to use the Spark View Engine, as it is basically just HTML. I basically want to create a chatbox, except pull the data written to my application's console every X seconds and display it in a box instead.
I have very little experience with JQuery and AJAX, but they aren't overly complicated from the examples I have seen. The issue I am running into is that ALL of the chatbox and shoutbox examples use PHP.
I basically just need something like this...
The only difference is I need to pull the information from my application instead. I can use basic C# methods inside of the HTML (and probably inside of javascript but I haven't tried this). What would be the best way to do this, and are there any examples floating around that don't use PHP?
This was completed using AJAX and JSON.
Well, to use HTML for styling inside some PC program is just not wise. It has much better UI engines, though. But for your information here is nice jQuery shoutbox tutorial, but well, you only need to handle data input and output with C#, so actually I see no problems. The engine which you are using should have some kind of data stream, or requests handler (bla://program/???)
I have a ASP.NET MVC project and i want to use jQuery on them. as other mention I put the jQuery on head section and found that they will work in firebug.
Now I want to jQuery in my C# class. how i can use them in C# class. I want to run the code but it's never compile where I goes wrong.
public class Manager
{
public static void Test()
{
// i put here jQuery code but they never compiler i try many time.
}
}
what is the right way to use jQuery in C# class. like in javascript code is work if I write but in c# when I want to try something like ajax request.
$.ajax is work fine in javascript but when I want to run them in C# they not compile. What is the right way to send ajax request from c# class.
Please tell me the way I can use jQuery ajax function in c# class.
The main reason you can't is because jQuery is a JavaScript library, not a C# library so it just won't work. However, I'm not sure why you would want to do that.
Your C# code is running server-side, so what does an AJAX request even mean in that context? You are already running code on the server, there is no need to remotely contact the server over HTTP. Just run whatever C# code you need to get the data you want. Using AJAX would be kind of like trying to call yourself on the telephone to ask yourself something.
I think you have a fundamental misunderstanding of how the web works. Javascript (JQuery is just a Javascript library) runs in the browser. Your C# code runs on the server.
The browser makes a request for a page from the server, which is your C# code (well, your code + whatever the ASP.NET MVC framework does for you) which sends a page to the client. This page can include Javascript which the browser executes.
Your server side code doesn't run Javascript (unless you're using a Javascript based server like Node.JS instead of ASP.NET). It can output javascript for the browser to run, but it itself does not run it.
Now as far making a AJAX request from C#, if you're trying to call something on your own site #JohnFx is correct that it would be pointless because you can just call the code directly without making a request.
If you're trying to fetch data from an external site, you can make an HttpRequest from C# as shown here. There may be some wrapper code that makes it easier to work with, but I don't know any off the top of my head (it's not something that's too commonly done). You'll then need to figure out how to parse the response.
JQuery is a javascript library and therefore JQuery code cannot be put into your C# code. In order for your JQuery to run, you must output it with the rest of your html and it will run in the users browser. JQuery is javascript and cannot run on the server with your C# code.
If you'd like to make a web request to a web page from c#, similar to what happens when you do an Ajax request from jQuery, look at the HttpWebRequest and HttpWebResponse classes.
This link is also a good place to start to learn a bit more.
As the other answers point out, you simply can't execute jQuery code from c# (and you shoulnd't) since jQuery is not a technology that's meant to run inside of ASP.NET, on the server. But instead, jQuery is a library of Javascript code that makes it easier to write Javascript scripts, which execute inside the user's browser. Everything that you can do with jQuery, you can also do with pure Javascript since at the core jQuery is just a collection of javascript functions and objects.
well, the jquery is a rich javascript library and javascript is a client side language. It should be used inside the dom.
c# is server side language which is rendered on the server when the request came into server.
You need to undrstand the difference between client side and server side. here is an example article
I'm currently using the HTML Agility Pack in C# for a web crawler. I've managed to avoid many issues so far (Invalid URIs, such as "/extra/url/to/base.html" and "#" links), but I also need to process PHP, Javascript, etc. Like for some sites, the links are in PHP, and when my web crawler tries to navigate to these, it fails. One example is a PHP/Javascript accordion link page. How would I go about navigating/parsing these links?
Lets see if I understood your question correctly. I'm aware that this answer is probably inadequate but if you need a more specific answer I'd need more details.
You're trying to program a web crawler but it cannot crawl URLs that end with .php?
If that's the case you need to take a step back and think about why that is. It could be because the crawler chooses which URLs to crawl using a regex based on an URI scheme.
In most cases these URLs are just normal HTML but they could also be a generated image (like a captcha) or a download link for a 700mb iso file - and there's no way to know be certain without checking out the header of the HTTP response from that URL.
Note: If you're writing your own crawler from scratch you're going to need good understanding of HTTP.
The first thing your crawler is going to see when gets an URL is the header, which contains a MIME content-type - it tells a browser/crawler how to process and open the data (is it HTML, normal text, .exe, etc). You'll probably want to download pages based on the MIME type instead of an URL scheme. The MIME type for HTML is text/html and you should check for that using the HTTP library you're using before downloading the rest of the content of an URL.
The Javascript problem
Same as above except that running javascript in the crawler/parser is pretty uncommon for simple projects and might create more problems than it solves. Why do you need Javascript?
A different solution
If you're willing to learn Python (or already know it) I suggest you look at Scrapy. It's a web crawling framework built similarly to the Django web framework. It's really easy to use and a lot of problems have already been solved so it could be a good starting point if you're trying to learn more about the technology.