I have a http handler that is called from a .aspx page in the form 1x1 pixel image. The handler has an extension of .jpg set up in the web.config. On all browsers apart from IE the http handler is called successfully from the body of the page when it loads.
However in IE the httphandler is not called.
If I call the http handler by entering the url in to the address bar in IE it works perfectly.
Any idea why it might not work in the body of the page?
IE may have it cached the image. If the filename of the .jpg isn't changing, I'd try to add a random query string to the end of it.
http://<path>/0104924934404624104049.jpg?random=<unix timestamp>
Related
In my app I want to load an html that contains an iframe with a remote url. This html is always the same, except for the iframe's src. What I do is hold the html in a string, and fill in the iframe url, than call NavigateToString(html). I get the iframe url from a REST API. I also get a baseUrl. If I merge those two urls into an absoulute url and set that as the iframe's src, the page won't load due to security reasons (it's a payment page). But if I set it without baseUrl, of course, the webview has no idea what's the baseUrl is, and the page also won't load.
In Android one could simply call webView.loadDataWithBaseURL. Is there something like this in Windows Phone 8.1? Any workaround?
(The problem is further complicated by that I also have to set Cookies to the webview.)
I came up with a solution, which works, and actually it's less hacky than it seemed to me at first.
I skipped NavigateToString. By using NavigateWithHttpRequestMessage, I can send a request to an URL, for example http://mybackend.com. I can set cookies as well (more information on this: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/a451d411-9312-4d40-80ee-112e166144ab/how-to-send-auth-cookie-in-webview-request?forum=winappswithcsharp). So far I have:
base URL set
cookies set.
Though, I haven't set my local html string yet. For this, in the WebView's NavigationCompleted event, I run a JS script like this:
await wvSecurePay.InvokeScriptAsync("eval", new string[] { "document.getElementsByTagName('html')[0].innerHTML = '" + htmlToLoad + "';"})
This will replace the current html content with the one I want to load. So I have my html containing the iframe with the relative url on a page which has the domain I need.
I would like to make a 1 pixel image that will reside on the html page to track page activity
I have a page http:/domain.com/mypage.htm
and I want to add <img src='http://www.test.com/myimage.aspx' /> somewhere in its body
When page is triggered I render an one pixel transparent image. I'm having an issue finding out the URL of the page that image is on. HTTP_REFERER header carrier the true referer of the page, and HTTP_HOST carries the URL of the image itself.
Is there a way to find out the HTML page URL that the image is on?
If you can't find it on any http header, you can always send some information like <img src='http://www.test.com/myimage.aspx?page=mypage' />.
If you can use javascript though, you don't need to display an image, use an ajax request instead.
You can analysis the request headers of myimage.aspx, the Referer header is the HTML page URL you're looking for. Besides, I suggest adding a timestamp with the <img> src link, like this:
<img src="http://www.test.com/myimage.aspx?t=1234567890" />
So that every time you refresh the HTML page, the browser invoke a new request to the image.
I'm trying to solve a problem where I'm intercepting a request in Navigating and want to inject an additional request parameter into that request before passing it off.
Here are the steps:
First I make a request via WebBrowser.Navigate(). I have an event handler to capture the Navigating event.
The request hits the Navigating event (before the actual request is made). I, at this point, want to either cancel the request and issue a new request with the added parameters, or somehow alter the current request to have the correct parameter.
Unfortunately I cannot simply call the Cancel event, and re-issue a Navigate call because of one problem. This request is from an iframe, so its one level deep, and the navigate call would clobber the end result of the document contents (as it would show only the iframe contents and not its parent's).
Any suggestions?
It seems impossible to inject a new parameter into a request on low level.
A recommended way is to alter html source of a page sends a request. For instance, add a hidden input field inside a form just after page is loaded. IMHO.
I have a flash image slider with a button below each image.
When i press that button, the user is redirected to a new page
where i add that image product to my cart.
The problem is that after doing the adding, i want to redirect the user back to the initial page.
The code:
protected void Page_Load(object sender, EventArgs e)
{
addProductToBasket(getCategoryIdFromUrl(), getProductIdFromUrl());
Response.Redirect(Request.UrlReferrer.ToString());
}
Please note that in Firefox is working fine but in IE or Chrome it is DOWNLOADING the swf...If i comment Response.Redict(...) the user remains on this page so the click button is working well, only the redirect seems to be the problem.
Any suggestions please?
Edit: The problem seems to be that Request.UrlReferrer keeps as link not the initial page containing the swf but the swf itself....
So, instead of doing redirect to:
http://localhost:1336/Site/Index.aspx
if does redirect to the swf contained on the Index.aspx page
http://localhost:1336/carousel/carouse.swf
Solved: with a session variable where i keep the initial page's url
It seems to me that it's a function of the flash player setting the referrer header differently in different browsers.
If that is the case, then you might want to have the flash player get the url of the page it is hosted on, and pass that as a parameter to your page, and then redirect to the contents of the parameter.
What I think you really should be doing though is registering an HttpHandler (IHttpHandler implementation) for the URL which performs the processing and creating a response which returns JSON or XML, which flash can easily parse.
This way, you don't have a page reload and you have a seamless experience.
What is the difference between Response.Write() and ClientScript.RegisterStartupScript()
Thank you.
The Response.Write method can be used to output code during the rendering phase of the page. The <%= %> server tag is a shortcut for <%Response.Write( )%>.
If you use Response.Write from the code behind, you will write to the page before it has started rendering, so the code will end up outside the html document. Eventhough the browser will execute the code, it doesn't work properly. Having something before the doctype tag will make the browser ignore the doctype and render the page in quirks mode, which usually breaks the layout. Also, as the script runs before anything of the page exists, the code can't access any elements in the page.
The ClientScript.RegisterStartupScript method is the preferred way of adding script dynamically to the page. It will render the script at the end of the form so that it doesn't break the html documnet, and it can access the elements in the form.
Also, you give each script an identity, which means that duplicates are removed. If a user control registers a script, and you use several instances of the user control, the script will only be rendered once in the page.
There is a huge difference.
Basically Response.Write will write to your response stream right now, normally this will put whatever you write at the very top of your page output, even before the tag (unless you call it after the page render event).
When you use RegisterStartupScript it will wait and write your JavaScript to the response stream after the page's controls have rendered (IE, the controls wrote their HTML to the response stream). This means the JavaScript you register will be executed by the browser after the other HTML before it has been loaded into the DOM. This is very similar to the event. Another thing this does is if “registers” the script so if you have more than one control on the page that both need that JavaScript they can check to see if it’s already been registered so it’s only rendered once and both controls use it client side.
Hopefully that makes sense, there are more details then that but I tried to keep it simple.
Response.Write
The Write method writes a specified
string to the current HTTP output.
ClientScriptManager.RegisterStartupScript
Registers the startup script with the
Page object.
As I think, both these methods are unrelated. Response.Write() can be used to write something on page that is rendered. While ClientScript.RegisterStartupScript() can be used for registering a javascript on page start up.