How to request an Asp.Net page manually? - c#

I have a project and it contains 2 pages: test1.aspx and test2.aspx. Now from test1.aspx I want to manually request test2.aspx and get the HTML out of it. I could do this using HttpClient or HttpWebRequest. Problem is I have a firewall and I suspect it won't work. Is there any other way to download the content from the webpage without actually using HttpWebRequest
Thanks in advance.

I don't really like what you are trying to do ;) Anyway, since your page don't seems to be a static page (.aspx) you must do a request to your webserver, whatever the method you use (HttpClient or HttpWebRequest).
Usually, a request done on the same machine does not passes through the network. If the DNS alias point to the machine IP address a loopback occurs.
In this case:
if your firewall is somewhere on your network, you don't care about
it, the request will not leave your host
if you speak about a firewall software, on your machine, it may block
the request. You may have to authorize such requests or force the DNS locally in your host file to specify 127.0.0.1 (which is a true localhost) and may work with
most firewall software
if you are on a Windows Server and your site require authentication, you may have to deal with Loopback
Check (or here)
NB: Loopbacks are usually considered as security breach and not recommended.
You should think about another solution like Ajax Web Services, Web or User controls (as already said) etc...

Related

Get response back from unpingable websites (C# ASP .net mvc)

I'm not a network expert, but for one of my projects, I need to ensure that the website I'm sending the request to is alive. Some websites do not respond to ping; basically, their configuration prevents response to ping requests.
I was trying to Arping instead of pinging websites, but Arping only works on the local network and will not go beyond the network segment (this).
I can download the whole or part of the webpage and confirm if the content is the same as the previous state, but I rather have one more level of confirmation before downloading Html.
Is there any other method that enables the app to get a response back from non-pingable websites outside the network?
Based on common practices you may use ping, telnet and tracert as a client to the requested server (at this point the website or the service you want to connect) and make sure the 3 command are enable to your side. You may also try to access it to your browser.
If its API you may also try to use POSTMAN and call the service.
Goodluck and happy coding :)

127.0.0.1 is not accessible from http. I have to use localhost that is not supported on android device

I'm not sure if this is a bug or not.
If it's a bug I already used github:
https://github.com/microsoftgraph/microsoft-graph-docs/issues/3106
if not I need help.
I'm using microsoft-graph for my game in Unity3d to store the save file on one drive user account.
Where I can use localhost everything works, but on android device I have to use 127.0.0.1 as localhost.
For dropbox and google I was able to do it... but microsoft-graph does not work with http on ip localhost like 127.0.0.1 it only works on http for localhost and it require https for 127.0.0.1... Of course HttpListener in c# for loopback only works for http (and since this is a game I need the user to use it on android without strange configurations).
I think this is a bug because boot dropbox and google give you the ability to use http for 127.0.0.1... but if it's not a bug how would you solve this problem? It is even possible to use https in a loopback with HttpListener or something like that without any strange configurations?
You should know that if I manually change the redirect url to http after the login I'm able to make it work.
The only problem is that I don't want to set up a server to redirect a user multiple times.. I want my game to look for the redirect url response in the localhost (that on android should be 127.0.0.1).
I need to know if it's possible to use https with HttpListener (or something like that) for 127.0.0.1 or you know how to workaround this problem without any webapplication.
var httpListener = new HttpListener();
httpListener.Prefixes.Add("http://127.0.0.1:" + anyfreeportonyourpc + "/");
httpListener.Start();
I am not sure if it is a bug or a feature you talking about but I have a few ideas you can try.
Probably the easiest way to workaround that is to use http://readme.localtest.me/ - This way you can use http://localtest.me:80 which is a public DNS record pointing back to 127.0.0.1 - Its nice for testing purposes but in this case quite a clever work around.
But as you mentioned it needs to be encrypted so based on the idea above you could to do this on one of your own domains. Get a certificate for it like free Lets Encrypt and just have that point to 127.0.0.1 and use that on your devices.
So say you have a domain called a.pl go and create a subdomain local.a.pl and set the A record on that sub domain to 127.0.0.1 (This would usually be a server with the web application but in this case we want to use it for a work around) Use lets encrypt to put a certificate on there so you can use HTTPS or maybe self signed will work too, I don't know.
Then in your code you do this
httpListener.Prefixes.Add("https://local.a.pl:" + anyfreeportonyourpc + "/");
Yes, you will initially need internet connection for your app to go and find the DNS record, and cache it on the mobile device. Setting the TTL to maximum will help to keep it cached for when there is no internet. So once its resolved you can use that domain for every single connection to the local device you need. It just requires that 2 seconds of internet to cache the DNS entry.
Another way to add a hosts lookup somehow... Not sure how but a simple local A record to myapp.local that point back to 127 in the hosts file. This would only be private level lookup for your workaround purposes but adding that record may not be straight forward on mobiles due to excessive abuse in the past.
It also just sounds like the graph server binding is only set to a hostname of localhost ... check to see if you can change that or relax it to an IP address. That would solve the root cause of your problem. I know these things have stupid bindings sometimes.
it's a bug. There is just no way to solve this problem if microsoft do not update their code.
EDIT. Finally a simple solution:
- just make a simple blog with wordpress
- activate https
- publish your blog in a free site like altervista
- install Insert Headers and Footers
- use this simple code
<script>
if(window.location.href.startsWith("https://yourblogaddress.altervista.org/blog/yourpostpath/")){
var stringPartUrl = window.location.href.substring(numberofcharinyoururl);
window.location.replace("http://localhostor127.0.0.1:yourport/" + stringPartUrl);
}
</script>
after that you just need to set https://yourblogaddress.altervista.org/blog/yourpostpath/ in the new azure portal app and change the OpenURL and redirect_uri in your app (but not the Prefixes.Add url that should be your 127 o localhost url).
Everytime someone log in should oauth to his/her microsoft account that should redirect to your https blog address that should redirect to localhost or 127 and get the code variable to your app that should finally be able to receive the auth code to upload/download files.
The main problem is that your blog should be online and you can only support one port (since you need to redirect one time). The best thing is that you don't need to change the implementation on desktop (since they allow again localhost with regular http in the new portal) and that you don't need a paid domain to do anything.

HttpWebRequest dot working with HOSTS file mapping?

I don't think this is duplicate of System.Net.WebRequest not respecting hosts file since I do not believe my issues to be proxy related (and it's making the request to localhost essentially).
So I've got a C# ASP page that makes an HttpWebRequest. Now, on this server I've done some custom mapping of some dev domains to the server's IP address.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( "http://someproject.dev" );
ERROR:
The remote name could not be resolved: 'someproject.dev' at System.Net.HttpWebRequest.GetResponse()
My Hosts file on the server (and my client) has 10.0.1.115 someproject.dev
I've also tried it with 127.0.0.1 on the server
Another note, both .net apps are running under hosts file/IIS mappings, i.e. one app is making a x-domain request to the other (which is permitted, i know that's not the cause because this works in our production environment).
Also, I'd like to avoid System.Net.Dns, unless you guys agree that's the only way it will work.
I would check your server. Any web calls that are made from the server are checked to see if the DNS is in the hosts file. Sounds like a server problem instead of a programming problem.

C# WebBrowser or Normal Browser

I'm getting "banned" message from a forum site cause of my windows application which tries to connect over webbrowser control by this code:
webbrowser1.Navigate("http://www.xyz.com");
I can connect without any "banned" message with my normal browsers both IE8.0 and FireFox 3.6. I cannot find any differences between my application and normal browser. It seems "banned" message is not related my IP address, cookies or header info (User-Agent, HTTP-Accept)
Please help: How can this forum site realize my request coming from normal browser or application?
Note: Sorry for my English. Thank you for your understanding.
At its most basic you're only sending the following information:
IP Address
Headers
GET data
There must be a difference in one of the above for the site to be able to differentiate between the browser control and your actual browser - There's simply no other difference unless multiple requests are involved.
I thing they banned the IP is your system IP not your connection IP who can be change but system IP can not.
some application set their agent like Firefox's user agent then server can't find that the request not come from browser they make them because they need that server can't find somebody going of their site by code not just using browser.
the answer i put nothing match to your question.
Fake identity means i tell about the request make by code inside a application not by browser user use.
the user-agent change make them as normal request that they can't find the request they have come by code not by browser.

Is it possible to redirect a url to another using a webproxy ( such as fiddler )

I'm trying to parse a WSDL file which is in another server but has hard codded "localhost" all over the document.
When I fetch it, obviously the program complains "connection refused" because nothing is running in my machine.
My question is: Is it possible to use a webproxy ( such as fiddler ) to redirect those localhost request to my other server so the WSDL references are complete?
:-/
Thanks
p.s. I could always have fixed the remote "wsdl" but the guy on charge will be here until next week and I would like to start working today.
You could use Fiddler as the proxy from your machine, and then have it rewrite the WSDL to change localhost to the correct machine name.
The FiddlerScript CookBook has an example on how to write this sort of script. Go to that page and search for "Remove all DIV tags (and content inside the DIV tag)". Just change the regex to match localhost and set the replace to the machine name you want to use.
If you have SSH access to the machine, you should be able to use SSH port forwarding to accomplish this. I'm assuming you're using Windows (based on the C# tag), so you can use Putty as explained here: Using port forwarding with PuTTY. Just follow those instructions to forward the desired port on "localhost" to the server that serves the WSDL.
Alternatively, if you're on a *nix based machine or a Mac, use SSH w/ the following command:
ssh -L PORTYOUWILLUSE:localhost:PORTONSERVER username#serverhostname
For example, if the WSDL were served on port 80, you could do
ssh -L 80:localhost:80 username#server
Once you're logged in (with either method), any requests to localhost on port 80 will be rerouted to the server.
If you only want to change it for a few minutes while you parse the WSDL, you might be able to change the HOST file and point "localhost" to the remote IP address. The hosts file is in "C:\Windows\System32\drivers\etc" in Windows VISTA/XP.
There's a few ways you could achieve this, none are particularly robust as long-term solutions, but you mention you just want something temporary until the dev gets back.
If everything after the domain matches (if your remote URL is otherwise the same as the localhost one), you can edit your localhost entry in your hosts file.
In system32\drivers\etc, copy the "hosts" file onto your desktop. Open in notepad and change this line:
127.0.0.1 localhost
Change the IP address (127.0.0.1) to your remote domain. Then copy the hosts file back into the etc directory. (Note: it's not possible to edit this file directly, as Administrator or otherwise).
If you have multiple domains on the remote web service, in IIS, you need to change the web site to serve for requests to "localhost", this might seem a bit odd, but it'll work because your machine will make requests to the server's IP address, but specify the request domain as "localhost". Right-click the website in IIS and select properties, then add the domain "localhost" to the list of HTTP-Header values supported by that web site. You can ignore all of this if your web site in IIS will serve content if you access it via an IP address. If that single IP address is shared between multiple web sites (which is usually the case), you'll get a "Bad hostname" error from IIS as it attempts to look up "localhost" and can't find which web site to direct the request to.
Another possibility is to use a personal proxy server called Proxomitron. It's a little old, and no longer under development, but it's very easy to setup and very solid.
Once you've installed it, open it and click "Config" - change the port it listens on to 80. Next you need to create a redirect rule (it's not actually a redirect, more of a rewrite of the url). You'll need to have a quick read of the docs to understand how to add your own redirect, but there's plenty of samples that ship with the app. The rule you're looking for is RDIR:
$RDIR( ) Is more sneaky and redirects the connection in Proxomitron without telling your browser. This is useful when you want your browser to think it going one place when, in reality, it's going somewhere else.

Categories

Resources