http meta refresh issue - c#

I am using http meta refresh to reflesh current page to keep session live. I am using VSTS 2008 + C# + .Net 3.5 and developing ASP.Net application.
My question is, is it possible to send from client (browser) side If-Not-Modified-Since request header to server side and check if at server side responses 304 Not-Modified header to client? (I want to use this to optmize bandwidth and overhead at server.)
If yes, could anyone recommend me some sample code at client side and at server side how to implement this?

This could potentially be addressed with the HtmlMeta class that was added in .NET 2.0. It allows programmatic access to the meta keywords. You can check it out here.

I'm not super familiar with ASP.NET, but in general, for something like this, consider using ETags.

You can use jQuery's Ajax api see the documentation here, there is a ifModified param. Moreover, the use of HTTP Meta Refresh is discouraged by W3C

You shouldn't use META Refresh. If you want to reload the page, use the JavaScript method window.location.reload(false);
I explain why here:
http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/meta-refresh-causes-additional-http-requests.aspx
and
http://blogs.msdn.com/b/ieinternals/archive/2010/07/08/technical-information-about-conditional-http-requests-and-the-refresh-button.aspx

Related

enable download on html from my asp page

I want to be able to download the html contents of my page from a client after receiving a post request (XMLHttpRequest and doing some processing. Is there a setting I must enable for this to be possible? I've tried enabling COORS via
Response.AddHeader("Access-Control-Allow-Origin", "*");
with no success. Has anyone found a solution to this problem?
Update: I am using ASP.NET Web Forms (with NET 4.5)
Well, I think the CORS stuff is for cross origin scripting - to enable JavaScript calls to a domain different than the original request. As far as getting the HTML contents, I believe you mean to get the response of the web server as it is posted back to the client. Not knowing what technology you have used (i.e., MVC, ASPX, etc.) you may want to look into interceptors. They differ depending on the technology. For ASPX, check out....
http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers

Who's the one making the HTTP request in this ASP.net code?

Title states the question.
doc.Load("http://weather.yahooapis.com/forecastrss?w=468739&u=c");
//parsing code goes here
I'm positive that it's the server that does the request, loads the document and parses it as opposite to the client using the page. However, a coworker says the contrary. We need to know this due to proxy authentication issues.
Thanks a lot!
WHO execute the code? Your ASP.NET page hosted on the server? Then it's the SERVER!
If you were executing the code is Silverlight or something like that, it will the client.

call a page within subdomain using ajax

I need to read a page content on my sub-domain using ajax get.
I thought of creating some script on my sub-domain and calling that script on my domain. however I don't know how to do it.
Is it possible to do such a thing? how?
EDIT:
I created a page in my domain that uses DownloadString and downloads that page and write down the result. any better ideas?
If you wish to support cross-domain AJAX requests, you will need to create a cross origin resource sharing handler (CORS). I don't have an example specific to asp.net, but if you are using MVC this is fairly simply to achieve (and would be fundamentally the same for WebForms).
A Web API example may be found here to get you started:
CorsHandler.cs
Also, if you need to support IE 7, 8 or 9 you would want to look in to a jQuery extension lib such as jQuery-ajaxTransport-XDomainRequest
EDIT
If you would like to look at a full example (again Web API unfortunately), here is a MSDN article with a full code example Implementing CORS support in ASP.NET Web APIs
You can also sometimes manipulate document.domain in JS. So if you're serving pages from www.site.com, and your Ajax services are hosted at app.site.com, set your document.domain to site.com.

Referencing jQuery CDN on a HTTPS secured page?

What's the preferred way of referencing a jQuery library on pages that use https? We have a checkout masterpage that needs to make use of jQuery UI widget but I keep getting an error:
Uncaught TypeError: Object #<Object> has no method 'dialog'
When calling the jQuery dialog. I've looked in chrome tools and the page is trying to get the library over https but it's location is defined as http in my markup. So what I'm asking is, how can i reference these libraries on secured pages? Do i reference a local copy within the site itself rather than a CDN? Or is there a https version that i can use?
Thanks
Google and Microsoft CDNs serve jQuery and jQuery UI through HTTPS as well. Just switch the protocol. E.g.:
https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
You can also just omit the protocol when referencing the external library:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
This way the script will be loaded using the same protocol as its document.
Both serve through HTTPS also, but the best way is to just not use HTTP part at all and use // only.
Example:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
By not using any HTTP protocol in your code, it means you need not worry about the conditional logic for whether it is actually needed or not. So your shopping pages won't have to be targeted specifically.
Hope that helps clear it up.
Thanks.

Is it possible to create a SOAP API using C# and JavaScript

I am looking to create a SOAP API using C# which I can then call using JavaScript. I use C# regularly but do not have any experience with creating API's. I would like to call the API using JavaScript as this will be used to submit form data from multiple websites not maintained by us.
If there is a better solution than SOAP I am open to suggestions.
If anyone can point me to examples or has any examples they can share I would appreciate it.
TIA
BrianKE
EDIT: I should have mentioned that I would to deploy a solution that will allow form data from multiple websites, not under our domain, to submit data directly to our database, hence the API. Perhaps there is a different way to handle this other than an API that I am not aware of.
If there is a better solution than SOAP?
If you are going to consume the API from javascript JSON is preferred. You may checkout this example which illustrates how to expose a JSON enabled WCF service for consumption from jquery AJAX.
Yes. You can.
Barring small issues/restrictions with XHR, it's perfectly "fine" to consume SOAP services from JS. The biggest issue is "dealing" with the XML, which can be more cumbersome than JSON (but it isn't bad if you use the correct tools such as XPath extractors). For my projects I use a small wrapper setup for the AJAX/XHR/SOAP call (not WSDL generated) that can take custom encoding/decoding functions.
Google searches shows several promising results/examples including JavaScript SOAP Client.
Note: If you need cross-domain access there are several methods including a proxy or the newer cross-domain XHR support (however, these require client and/or server support) or, depending on client, just really relaxed settings. These cross-domain considerations are generally no different than if using "REST" or other web-service APIs.

Categories