Referencing jQuery CDN on a HTTPS secured page? - c#

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.

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

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.

HttpRequest and javascript - can you mimic actual browser behavior with regards to javascript with C#?

I'm posting some form values to a form using HttpWebRequest. The problem is that the post behaves differently depending on javascript function call results. Javascript runs on the client browser, so I'm doubting I can get around this problem, but does anyone know a way of mimic-ing a browser's behavior with regard to javascript from C# code?
Alternatively, is there a way for me to manipulate Internet Explorer to get and post values to different URLs from a C# Windows Service? Can it be done with a WinForms app?
Yes, you can automate browsers from any .NET application using an automation framework:
Selenium
WatiN
You can run Javascript in cscript.exe. You don't get the browser API, but you can use Javascript libraries, can do AJAX, XMLHTTPRequest, etc.
You can also use a MSHTML control within a C# app to retrieve a web page. That is effectivedly embedding IE into your app, including running browser-side Javascript.

http meta refresh issue

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

Switch back to http from https in SharePoint (MOSS 2007)

I have a MOSS 2007 instance and a web app (Site Collection) in port 80 that has an extension through port 443 to enable https.
This instance has an asp.net web app that is inside the Site Collection. This asp.net web app enters https protocol when one of its qualifying aspx webforms is called, but when the user leaves the form the https protocol is still active for the rest of the navigation.
You must know this:
All site content pages must be and are sharepoint pages (site content).
All URLs are and must be relative.
The asp.net web app is using an http module that can handle http-->https and viceversa (it works by overriding the page_load event).
I'm looking for a native way to do this in SharePoint (MOSS 2007) or using IIS.
Have you tried to link the user to http://./server-relative-url at the end of your custom form? I don't know if this will work but its the best I can think of if you must use relative URLs.
Edit:
I don't like the 'feel' of it, but the only thing I can think of right now is to use an HTTP module to update the https links in the page. If it's SharePoint-generated content that you need to update en masse then this is practical and efficient, and perhaps the only option?
You would need to work out some logic (maybe add something to the page) so the HTTP module knows when to activate.

Categories