Okay I know c# got a vast and very ease to use application development programs but this is what i want to learn now.So when user opens his browser and enters some url in it. Is it possible to send this data or the entered url addressto some other code one such a c# code or some other example c++ which is located on his hard drive.
To be simple when user clicks some link on a webpage or enters some url or closes the browser or when he opens the web browser, Can we detect all his actions that he perform on web browser through c# code or anyother way(I guess add-on or pluins the way it works) but Is it possible to send his actions to c# code and program it and give certain output back to browser so that browser performs it and outputs to user.
Something like browser-->c#code-->website.. I want c# code to act between the browser and webpages.
work I tried so far
I started googling on this and learnt little about how browsers work but still unable to find the solution. However I guess plugins are the way to do such tasks and found firebreath cross platform,a way to develop plugins for browsers. So is this possible by plugins? if so could you suggest me some good tools to develop my own plugins. Thanks
There are several options depending on what you want to achieve:
Proxy
You could implement a http proxy and configure the browser to use that proxy. The proxy sees all traffic and can do whatever it wants... this works rather "browser-agnostic". See the links here and here.
PlugIn
You could implement a plugin... alhtough this a browser-specific... for example IE used to have BHOs to this kind of stuff (not sure whether this is still possible with IE10...). Some options can be found here, here, here, here and here.
You can use FiddlerCore for this
Fiddler.FiddlerApplication.BeforeRequest += sess =>
{
Console.WriteLine("REQUEST TO : " + sess.fullUrl);
sess.bBufferResponse = true;
};
Fiddler.FiddlerApplication.Startup(8877, true, true);
Console.ReadLine();
Fiddler.FiddlerApplication.Shutdown();
System.Threading.Thread.Sleep(750);
After running this code, open your browser and navigate to any page.
Related
I am developing a Facebook WPF application for my senior design project in college. I've never coded in C# or developed a WPF application before this. Right now I'm trying to implement logout functionality. I'm using a WebBrowser to do this, and the documentation seems to say that the method of doing this is to navigate to:
https://www.facebook.com/logout.php?next={redirectURI}&access_token={token}
in the browser, where the sections in curly braces are variables. For some reason, it brings me back to the Facebook home page (news feed) every time I do this. Is this due to a change made by Facebook in recent years or is there an error on my part? Alternative methods of logging out via a web browser, such as an alternative logout URL, would be appreciated as well.
With FB SDK V6, there are some nuances. I'll delve into a few things you need to verify in your code. Your code probably would've worked with previously, but today you should make the following changes, assuming you haven't already:
The redirectURI in your code needs to be changed to "http://www.facebook.com". Standard redirect URIs (including those associated with your access token generation) don't seem to work anymore.
You also need to make sure your redirectURI is an absolute URI. There is a very simple way to do this, which I will show in the code below.
Bringing it together, this code will work for the current FB C# SDK via a WebBrowser:
var fb = new FacebookClient();
var logoutURL = fb.GetLogoutUrl(new { access_token = {userAccessToken}, next = "https://www.facebook.com/"});
WebBrowser1.Navigate(logoutURL.AbsoluteUri);
A final note is that in my code, I chose to ask for the logoutURL instead of hardcoding it. It looks like after making the changes your logoutURL would still be correct, but it may be beneficial to retrieve the url to help ensure correctness. Good luck on your project.
I am working on a c# .NET website in which the user can click on a link and get redirected to another web page in a separate website also owned by us. The code is very easy to understand, there is a switch followed by a call to Response.Redirect(the_url_we_want_to_go_to).
I have debugged it numerous times and I can confirm that when the debugger hits this redirect line that the parameter is correct. It points to the QA version of this other website. qa.samplesite.com lets say. However, the browser does not go there. The browser instead hits the test environment instead. Lets call it test.samplesite.com. This is the problem.
I understand there are a million things in between the app servers these two separate websites are on, but maybe one of you has seen something like this before. More specifically, is there a way to catch outbound traffic in the debugger or is there a way to see outbound traffic on the app server itself (in IIS)? I am familiar with intercepting inbound traffic inside of httpmodules. Maybe this isnt a stackoverflow question...
Thanks for your help!
Use the very nice HTTP sniffer "Fiddler". It will allow you to see all HTTP requests. You should verfiy that a) the redirect target is correct (it might be overwritten later in the request pipeline. A Response.Redirect is not the final word) and b) that you don't have a second redirect after the first one.
You can try using the overload of Response.Redirect as
Response.Redirect("url_here", true);
This will stop the response on current page (as endResponse is set to true) and redirect to the url.
If you still have the issue, then this might be some name resolution error.
Check to see you your hosts files in the windows directory found here
C:\Windows\System32\drivers\etc\hosts
Hope this will do it.
I finally figured a similar issue I had. It was quite silly. I had copied some .aspx pages making minor changes. The page where I tried to redirect the client, had it's "CodeBehind" setting wrong. So it redirected to the right page, but loaded the CodeBehind from another page!
I'm sorry if this subject has already been answered, but I couldn't find what I needed (yet).
I'm working on a program that downloads files from university websites that use the same infrastructure. It's an open source project which I'm trying to support in my free time
(hosted in goodle code: http://code.google.com/p/highlearner/)
Until now we used GET and POST requests to login into the right page and download stuff. But the universities keep changing their websites and every little change requires teaking in Highlearner, which requires a new version, auto-updating all users, etc. Also, every university has its own login page, requiring me to tailor a login sequences..
So I'm looking for a more robust solution. Instead of manually redirecting and setting the HTTP parameters. Is there some kind of mini browser that supports with HTML + Javascript? No GUI is needed, I just need the engine.
This way, I will simply need to fill out the form parameters and let the browser do the work.
Thanks,
Nitay
You could try to automate the process with WatiN library . It allows you to click buttons, submit forms, etc.
using (var ie = new IE(loginUrl))
{
if (ie.TextField("username").Exists
&& ie.TextField("password").Exists)
{
ie.TextField("username").Value = "username";
ie.TextField("password").Value = "password";
ie.Button(Find.ByName("submit")).Click();
}
}
I use Process.Start("firefox.exe", "http://localhost/page.aspx");
And how i can know page fails or no?
OR
How to know via HttpWebRequest, HttpWebResponse page fails or not?
When i use
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("somepage.aspx");
HttpWebResponse loWebResponse = (HttpWebResponse)myReq.GetResponse();
Console.Write("{0},{1}",loWebResponse.StatusCode, loWebResponse.StatusDescription);
how can I return error details?
Not need additional plugins and frameworks. I want to choose this problem only by .net
Any Idea please
Use Watin to automate firefox instead of Process.Start. Its a browser automation framework that will let you monitor what is happening properly.
http://watin.sourceforge.net/
edit: see also Google Webdriver http://google-opensource.blogspot.com/2009/05/introducing-webdriver.html
If you are spawning a child-process, it is quite hard and you'd probably need to use each browser's specific API (it won't be the same between FF and IE, for example).
It doesn't help that in many cases the exe detects an existing instance and forwards the request there (so you can't trust the exit-code, since the page hasn't even been requested in the right exe yet).
Personally, I try to avoid assuming any particular browser for this scenario; just launch the url:
Process.Start("http://somesite.com");
This will use the user's default browser. You have to hope it appears though - you can't (reliably and robustly) check that externally without lots of work.
One other option is to read the data yourself (WebClient.Download*) - but this may have issues with complex cookies, login, user-agent awareness, etc.
Use HttpWebRequest class or WebClient class to check this. I don't think Process.Start will return something if the URL not exists.
Don't start the page in this form. Instead, create a local http://localhost:<port>/wrapper.html which loads http://localhost/page.aspx and then either http://localhost:<port>/pass.html or http://localhost:<port>/fail.html. localhost: is a trivial HTTP server interface implemented by your app.
The idea is that Javascript gives you an API inside the browser, which is far more standard than the APIs on the outside of browsers. Since the Javascript on wrapper.html comes from the same server and even port as the subsequent resources, this should satisfy the same-origin policies in current browsers.
I am developing an application in which I am displaying products in a grid. In the grid there is a column which have a disable/enable icon and on click of that icon I am firing a request through AJAX to my page manageProduct.aspx for enabling/disabling that particular product.
In my ajax request I am passing productID as parameter, so the final ajax query is as
http://example.com/manageProduct.aspx?id=234
Now, if someone (professional hacker or web developer) can get this URL (which is easy to get from my javascript files), then he can make a script which will run as a loop and will disable all my products.
So, I want to know that is there any mechanism, technique or method using which if someone tries to execute that page directly then, it will return an error (a proper message "You're not authorized or something") else if the page is executed from the desired page, like where I am displaying product list, then it will ecxecute properly.
Basically I wnat to secure my AJAX requests, so taht no one can directly execute them.
In PHP:
In php my colleague secure this PHP pages by checking the refrer of the page. as below:
$back_link = $_SERVER['HTTP_REFERER'];
if ($back_link =='')
{
echo 'You are not authorized to execute this page';
}
else
{
//coding
}
Please tell me how to the same or any other different but secure techique in ASP.NET (C#), I am using jQUERY in my app for making ajax requests.
Thanks
Forget about using the referer - it is trivial to forge. There is no way to reliably tell if a request is being made directly or as a response to something else.
If you want to stop unauthorised people from having an effect on the system by requesting a URL, then you need something smarter then that to determine their authorisation level (probably a password system implemented with HTTP Basic Auth or Cookies).
Whatever you do, don't rely on http headers like 'HTTP_REFERER', as they can be easily spoofed.
You need to check in your service that your user is logged in. Writing a good secure login system isn't easy either but that is what you need to do, or use the built in "forms authentication".
Also, do not use sequential product id's, use uniqueidentifiers, you can still have an integer product id for display but for all other uses like the one you describe you will want to use the product uniqueidentifier/guid.