Get url from iframe or any other control - asp.net

I've an aspx page with an iframe control which host cross domain site. I'would provide a simple tool to allow user a fast "copy-past" frame url in an asp.net textbox.
Obviously, since my IFrame point to external site this kind of action is denied for security reasons.
Is there any way to get current frame url in a cross domain scenario?
I can use whichever different solution from iframe, it really isn't important for me.

If you're looking for javascript solution then this could be it:
HTML:
<input type="text" id="url" />
<button id="go">Go</button>
<br />
<iframe id="browser" width="300px" height="300px"></iframe>
Javascript:
$(document).ready(function(){
$("#go").on("click", function(){
var url = $("#url").val();
$("#browser").attr("src", url);
});
});
http://jsfiddle.net/bBhc4/
"Diving deeper" into iframe elements would cause same origin policy restrictions though

Related

How to set up a content locker with captcha but exclude search bots?

I want to set up a content locker to prevent users from scraping my website but still allow search engine bots to see the full content, somehow exclude the code from being applied to bots, only to visitors.
The content locker doesn't really need to be very advanced, it can be a simple captcha challenge or even just a simple button like this one:
<script type="text/javascript">
function showDiv() {
document.getElementById('welcomeDiv').style.display = "block";
}
</script>
<div id="welcomeDiv" style="display:none;" class="answer_list" > WELCOME</div>
<input type="button" name="answer" value="Show Div" onclick="showDiv()" />
Can anyone help me out please?

sending page URL with form asp

What I'm trying to do is to send the a form with the page url in it.
<asp:TextBox ID="tbAutContactSubject" runat="server" Text="" CssClass="text" onblur="if(this.value=='Page.Title') this.value=this.defaultValue;" onfocus="if(this.defaultValue==this.value) this.value = 'Request.Url.AbsoluteUri';" />
I am new to asp, i figured if i could just get the subjects onfocus to display the page url (dont even know if you can do that) it would be a start.
Any help is much appreciated!
You can get the current page's URL via JavaScript, like this:
window.location.href
You can also redirect the browser to a URL by setting the window.location.href property, like this:
window.location.href = "YourPage.aspx";

Avoid browser cache in asp.net

I try to disable the html url browser cache using programmatically.
I am developing as a site using asp.net, I need to disable the html url browser for the security reason.
I tried many ways to disable the cache but none seems to work. Any ideas?
<iframe id="iframe" src="http://www.phy.mtu.edu/basiccomputing/sample.html" runat ="server" width="200" height="300"></iframe>
As far as it's a html file you want to work with, a easy solution is to append a random number and the end of your url like this
<iframe id="iframe" src="http://www.phy.mtu.edu/basiccomputing/sample.html?12345" runat ="server" width="200" height="300"></iframe>
I don't know wich view engine you are using, so i cant provide a sample you simple copy and paste.
You have to replace ?12345with a random number like new Random().Next().ToString()
If you call a asp.net page you can control it with
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.Cache.SetNoStore();
more informations about that:
ASP.NET Cache Examples
hope this helps
You could attach a random parameter to the URL so the browser thinks it's a different page every time.
http://www.phy.mtu.edu/basiccomputing/sample.html?rand=[INSERT RANDOM HERE]
try
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)). This site has something that can be quite helpful.

ASP.Net: Get page url from inside a frame

How can I get the top page URL from inside a frame?
(in javascript it's implemented using : window.top.location)
You can't.
The fact that the page is going to be loaded into an iframe in another page is not sent in the request to the server, so it's not possible to get the ULR of the parent page, or even to determine if there is a parent page or not.
If you need that information on the server side, you have to add that information to the request, for example by including the parent page URL as a querystring parameter.
In case people need it, there's a way for this certain purpose. At least I solved somehow.
First, place a button running at server, add a click event and a client-click event.
<asp:Button ID="btnFindParentUrl" runat="server" Text="Get Url!" OnClick="btnFindParentUrl_Click" OnClientClick="fillHidden();" />
Put a hidden textbox inside a div with style="display: none;" (not Visible="false" for button because if you do client can't see and fill it):
<div style="display: none;">
<asp:TextBox ID="txtHiddenUrlField" runat="server" BorderStyle="None" Font-Size="0px" ForeColor="#F6F6F6" Height="0px" Width="0px"></asp:TextBox>
</div>
Now place javascript code of fillHidden() function:
<script type="text/javascript">
function fillHidden() {
document.getElementById('<%= txtHiddenUrlField.ClientID %>').value = parent.document.location.href;
};
</script>
That's all you have to do at client side.
Let's go to the server:
protected void btnFindParentUrl_Click(object sender, EventArgs e)
{
string parentUrl = txtHiddenUrlField.Text;
}
This way, you should be getting parent url from button in an iframe.
Anyone needs help may ask question here or to this code's post in my personal site.
you can do this if the frame + parent are both on the same domain. if so, then you can obtain references to other iframes, frames or pop-ups.
from memory, try window.parent, so yours would be something like window.parent.top.location

ASP.Net Form send click but nothing happens

I am building a german payment provider into my site.
But when I click on "Submit", nothing happens. Can someone please help me? I think I've looked at it too much and I can't see the forest for the trees anymore...
<form method="post" action="https://www.sofortueberweisung.de/payment/start">
<input name="currency_id" type="hidden" value="EUR" />
<input name="reason_1" type="hidden" value="Zambuu" />
<input name="user_id" type="hidden" value="29593" />
<input name="project_id" type="hidden" value="80145" />
<input type="submit" value="Absenden" />
</form>
Okay, so it's a little bit unclear what I want, it seems:
I have a lot of asp-sites allready, and now I must send, however, the information that is given by the hidden inputs by post-method to the site "sofortüberweisung.de/payment/start".
However I can solve it, it's not nessecary, there is no need for a form-tag, if there is another solution (e.g. with the code behind).
So: How can I send a lot of post information (these here is only an exmaple, in the real site there are a lot more) with code and redirect it to the right site?
If the code you have provided is within a standard ASP.NET form, so that you have nested form tags, try the solutions provided to this Stack Overflow question.
If it is possible to have this page be a simple html form, that is another possible solution.
Your button needs to have the runat="server" attribute set and it might be worth doing the same on your form atttribute.
Also remember in asp.net webforms you can only have one form tag.
I've had this issue a couple of times before where when creating an HTML form inside an ASP.NET form tag, the inner form just wouldn't post out.
One solution for me was to adjust the ASP.NET form tag wrapper for that page (moving the close above the HTML tag).
Another (where I needed ASP.NET controls obove and below the HTML form) was to add an iframe, passing the parameters for the form post to the iframe URL. Using JavaScript, the iframe then used those parameters to post the form to a new window/the parent window. Probably better ways, but it worked for me.

Resources