i saw this article on msdn forum about Request.UrlReferrer but didnt really understand it well. I need to use this property in one of my pages to see where the user is coming from. My case is if the user comes from certain page, i need to have an if condition and should open up a popup as well as redirect page to next page. if the Request.UrlReferrer is null then i dont need the popup, just goto next page. can somebody put a sample code snippet here?
this is what i have so far -
Public ReadOnly Property URLReferrer() As uri
Get
End Get
End Property
i am not sure what to put with the Get and End Get.
UrlReferrer is already a property of the Request, you don't need to declare it. Just use the instance of the Request from the Page object (assuming web forms). Page.Request.UrlReferrer
Related
I've been trying to figure this out using various different methods. I'm trying to create a script/bookmark or some type of quick action to open a browser tab or window with a specific URL, and automatically log me in using my credentials. I'm not all that concerned about security for this at the moment.
At first I figured I'd try to use a javascript bookmark to do this, but nothing I found in my research worked. Next I tried to create a bash script, but I couldn't figure out how to send the credentials in via the terminal. Most recently, I literally copied the source code of a site, created a local file and tried to hack together something where I could prefill the form data with credentials and use JS to submit the form, and I've gotten close with this, but for some reason when I use the JS submit function, it errors out and says that the username and password are invalid. But when i turn off the submit function and manually click "log in" on my local html page, it works as expected. I want this to be a one click process, so the idea of using onload/submit or something to that affect is really important to me.
The site I'm testing with has a Rails backend and my next attempt might be trying to use POST to do what I'm thinking, but that's currently outside of my level of knowledge on the subject.
Anyone answering: i do not want to use a password manager to accomplish this.
My requirement is that i will either be able to a) run a script or b) use a 1-click option to do this per website. Ideally i'd be able to set this up in a sort of programmatic way to do this with multiple sites, but I'd be happy with 1 at the moment.
i know similar questions have been answered before, but I haven't been able to use information from those posts (the ones I've seen anyway) to figure out a good way to do this.
Create a bookmark for the current page you have opened.
Edit the bookmark
Change the value for the URL to something like this.
(javascript:(function(){CODE_GOES_HERE_FROM_BELLOW})();
find the field for username and password on the page.
Given example for hotmail
var inputs = document.getElementsByTagName('input'); for(var i=0;i<inputs.length;i++){if(inputs[i].name === 'passwd'){inputs[i].value = 'YOUR_PASSWORD'}else if(inputs[i].name === 'loginfmt'){inputs[i].value = 'YOUR_USERNAME'}}; document.getElementById(document.getElementsByTagName('form')[0].id).submit();
OR
try out casperjs.
The proposed solution didn't work for me and rather than spending tons of time installing a testing framework that I'll never use other than for this purpose, I decided to try to do this another way.
First, I found out that the reason my JS wasn't working before is because the site did not allow a JS submit to be done, or atleast that's what it seemed to be when I got this error: "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience"
The javascript I was using was in fact working, just not submitting. I used the following code to fill the fields (using "Class Name" elements on the page since there was no name or ID):
document.getElementsByClassName('username')[0].setAttribute('value', 'user');
document.getElementsByClassName('password')[0].setAttribute('value', 'password');
As I mentioned, the problem was when I tried to use JQuery to submit the form: document.getElementsByClassName('loginForm')[0].submit();
Which is when the above error cropped up. I can't really say for sure whether this is the root of the cause, but the page does submit, but I get an invalid username/password error when I do
I haven't figured out a great way to get around this just yet, but my short-term, "hacky" solution was to use Applescript to send a return keystroke to the browser to submit the form. I'd ideally like to figure out how to get the submission to work using JQuery, but I'm not sure how to get around it.
I would like to get the values of this div shown in the link that I propose.
Is there some kind soul who could show me the solution? I'm not here to ask for the code, but are diffcult and would like some help.
I'm trying to use the WebBrowser control, but so far nothing.
Dim divs = WebBrowser1.Document.Body.GetElementsByTagName("div")
Dim result
For Each d As HtmlElement In divs
If d.GetAttribute("className") = "block_competition_tables real-content clearfix " Then
result = d.InnerText
End If
MsgBox(result)
Next
Image example:
http://www.mediafire.com/convkey/e9de/4ju6fo9cp6ibl84fg.jpg
Site link:
http://it.soccerway.com/national/italy/serie-a/20142015/regular-season/r27139/
The problem is probably because your using className as the attribute name, when it should be class.
Have you tried getting the div by id
page_competition_1_block_competition_tables_8_block_competition_form_table_1
instead, it wont break if they change the css that way (although it may still break if they change the layout but you will probably have other issues to fix then anyway).
EDIT:
Ahh figured it out, not only does that page not seem to work well in a web browser control (lots of javascript errors on my windows 8 box) the table is loaded dynamically when you click the link so its not there when you try get it.
If you look at the network tab of developer tools in chrome (or in whatever browser you use) it'll show a GET request to
http://it.soccerway.com/a/block_competition_tables?block_id=page_competition_1_block_competition_tables_8&callback_params=%7B%22season_id%22%3A9757%2C%22round_id%22%3A27139%2C%22outgroup%22%3Afalse%7D&action=changeTable¶ms=%7B%22type%22%3A%22competition_form_table%22%7D
which if you decode the URL params is
http://it.soccerway.com/a/block_competition_tables?block_id=page_competition_1_block_competition_tables_8&callback_params={"season_id":9757,"round_id":27139,"outgroup":false}&action=changeTable¶ms={"type":"competition_form_table"}
going to the url gave me the html of the table in a json object, and you can do that with a simple HTTPRequest instead of using a webbrowser.
Hope that helps.
in my master page init sub I have a block of data/text being written to a control. The basic idea was that it should be available on every page (obviously). However, I have come across a situation in which I need this to NOT happen on a certain page. Is there anything I can do, short of making a new master page for this specific page, to make this work? I also use a basepage, if that ever needs to come into play. Thanks!
Make a virtual readonly property in your base page class called ShouldDoThingy that always returns false.
Override it in this specific page to return true.
In the master page, check if (((BasePageClass)Page).ShouldDoThingy)
If it is only a page or two and you don't have a basepage class you can use as suggested by SLaks, you can always just check the current request url:
If Context.Request.PathInfo.ToLower.Contains("/pagename.aspx") = True Then
'do something
End If
I need to POST a HTML form to a 3rd party website (a Mass-SMS texting system).
In the past I've done this by forwarding to a page containing a form I've pre-populated and hidden (using display:none), then I've ran a javascript function at the end of the page to automatically submit this form.
However I'm hoping theres someway I can do all this programmatically (as I don't care about the response, and the user doesn't need to see the page the form is being posted to).
How can I do this? Cheers
You could use a WebClient.UploadValues method to send an HTTP POST request to a remote server from your code behind. Just fill up the name/value collection with the values coming from the hidden fields.
If you're willing to get into PHP, you can very easily use cURL for this.
Otherwise it's going to be quite difficult using just Javascript.
See here for a detailed tutorial.
Here is the brief detail of issue.
I have Page1 where I have put LinkButton. The LinkButton Has property PostBackUrl pointing to Page2.
When user is redirected to page2, I am using Page Load method to access controls from previous page & get the needed value. To make clear, I am using this approach becuase I cant use querystring.
Page 2 has 2 web parts on it. The web parts use data received in Page Load event from page1 and renders data.
This works perfect on first page load. When user clicks on a URL in page which posts back, the web parts gets lost.
Note that if I come directly to page2 without going at page1, then web parts are retained in the page and they are not lost.
Can anyone give me the clue of issue cause?
Thanks in advance.
Do you have any debugging enabled? you are most likely looking for values on page load that don't exist and might be getting exceptions that aren't handled properly.
I am not sure why but somehow code was throwing an exception when I tried to access the property Page.PreviousPage. Though I had made sure to check null on each step. Even code was never get hit when web part was lost. So it is still a mystery for me.
Just in case someone comes across this issue my workaround may help. I used Post back to page2 using post method. I accessed the variables using Page.Form[] variables. This way my issue of getting web parts lost got resolved.