DNN module doesn't include css/js when in view mode - dotnetnuke

I have a DNN module that I wrote that includes the css/js for the jquery fancybox plugin like so:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="DotNetNuke.Modules.WebPortfolio.View" %>
<%# Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<dnn:DnnCssInclude runat="server" priority="10" FilePath="DesktopModules/WebPortfolio/Scripts/Fancybox/jquery.fancybox.css" />
<dnn:DnnJsInclude runat="server" priority="10" FilePath="DesktopModules/WebPortfolio/Scripts/Fancybox/jquery.fancybox.pack.js" />
When I'm in Edit mode, everything is fine and dandy, but when I switch to View mode, the css and js are not included. This seems fairly simple, so I guess I'm missing something, but what? Why aren't the scripts loading in View mode?
DNN version is 6.2.4
Edit: I've been fighting with this all last night and this morning. The script loads every time in Edit mode, but when in View mode or logged out, it loads maybe once or twice, then fails to load. Interestingly, I added a server side timestamp to the module's view control and disabled all caching (browser, DNN host settings) and the file is still being cached. This occurs on both my local machine (IIS Express) and our staging server (IIS 7.5).
If I bounce the web server and clear the Portals/0/Cache directory, the script occasionally loads the first time, but fails after that. I've finally resorted to a client side check which loads the script dynamically if necessary, but that circumvents the goodness of the client resource management API, so I'd really like to figure out a proper solution.

This sounds like an issue that I just logged (DNN-20363), where resources registered with the Client Resource Management Framework aren't included when the module is cached. I was running into this when the module had module caching on. Does your module have a default cache time set in its module definition? You might try turning that off and then adding a new instance (to make sure that the caching setting itself isn't getting cached).

Related

How to reload "index.html" in angularJS without manual intervention?

I have a website developed in AngularJS, and index.html serves the root of the application.
All the JS and CSS versions are maintained in the index.html itself, which means for any changes to reflect to the user, "index.html" is to be reloaded at the browser.(correct me if I am wrong here).
This is a problem, since there could be chances that the user has a tab opened of our website in his browser and we have published a new release. This release will not be published at user's browser till the time a "Manual refresh" is not triggered and "index.html" is not reloaded and hence bring up the possibility that the user will not be using our latest release.
We have written a framework to reload all resources once a release is detected by sending the latest version from web-server and comparing this with the current version in the browser and trigger a reload automatically. This fix works fine, but the problem again is, how to publish this release first time to all user's browser?
I hope you get my problem? let me know otherwise.
This is not possible. There is no way to force an open page to refresh if it does not already have code to implement that feature. You will have to wait until the user refreshes it themselves, and the browser cache expires, and any intermediate caches between the user and your servers.
I recommend searching to learn about "HTTP caching" if you are not already familiar, as well as "cache busting." In general, you may want to consider making index.html a small file that references your big files in <script> tags, setting the cache control for index.html very low, and use cache busting techniques on your big files.
But for your first release, there is no way to invalidate open tabs or existing caches. If this will cause a problem with your server, read up on "API versioning" for different ways to handle it.

Publishing ASP.NET MVC/AngularJS Application

I'm working on an ASP.NET MVC application with an AngularJS front-end and it's working great when running from visual studio/iis express, but not so great when I try to publish it so it's accessible to other users (e.g. navigating to http://server/application in a browser). I have IIS configured on server so that http://server/application points to an "application" folder that is structured as:
application
app
areas
foundation
main
layout
layout.html
bin
Content
fonts
Scripts
Templates
Views
Shared
_Layout.cshtml
Index.cshtml
Logs
Global.asax
web.config
The initial page, Index.cshtml (under Views/Shared/), gets loaded but includes this:
<div ng-include="'app/main/layout/layout.html'"></div>
which returns a 500.24 - Internal Server Error.
If I change the ng-include to:
<div ng-include="'application/app/main/layout/layout.html'"></div>
then the published application works but running it from visual studio/iis express returns a 404.0 - Not Found response when trying to load that layout.html file, I'm assuming because there's no parent "application" folder when it's running using iisexpress.
I did manage to get the published application working at one point by copying the contents of the published application folder to server's C:\inetpub\wwwroot folder but that doesn't seem like a proper solution, so what's the best way to inform Angular to look in the correct location for this ng-include?
What I ended up doing is adding an application path variable in my web.config file and prefixing all my ng-include or other urls with the application path, so they looked like
<div ng-include="'application/app/main/layout/layout.html'"></div>
and then updating my project Web properties to the following:
so that whether I publish it or run it through Visual Studio, it's running under the 'application' folder and looking for the html files in the appropriate location.

Can I host my Silverlight XAP file from a Azure Blob or CDN?

Having clients over the globe, we encountered some serious loading delays for initially retrieving the XAP from various locations. The hope was that we could host the compiled XAP in the cloud, offering a closer download depending on the end-user's location.
We are using RIA services, but the service endpoints need to remain on our local server, because of data connections, connections to internal services, etc.
How do we distribute the XAP using cloud-based services, while having it continue to function the same as it does currently?
EDIT: Since I worked through this and found the answer myself, I've moved the steps that I had accomplished before out of my question and into the answer to better facilitate a good Q&A format and for anyone else approaching the problem from step zero.
After hammering away at this, I found the solution to get it almost completely working.
Update RIA service endpoints with absolute URIs to refer back to the hosting page rather than relative to the XAP location itself.
Ensure all image (etc.) content is loaded from either resources in the XAP or else ensure they are uploaded as well to the Azure Storage Blob. Any relative paths will try to resolve to the XAP location.
Generate the XAP file and upload to the Azure Storage Blob. You will need to ensure that the XAP has Content-Type of application/x-silverlight-app. I accomplished this using Azure Storage Explorer. You can set Content-Type by opening the properties of the item via double-click, but, and even better, you can click the Settings gear to 'Edit Content Types' and add a rule that .xap is application/x-silverlight-app so that it will be automatically set any time you upload.
Ensure you have a proper cross domain policy in place.
Update your hosting page to supply the new source. Additionally, you will need to add the enablehtmlaccess param if not already set, since this value is false by default for cross domain.
For item #1, I accomplished using code such as the following:
var u = HtmlPage.Document.DocumentUri;
Site = u.AbsoluteUri.Substring(0, u.AbsoluteUri.LastIndexOf('/'));
MyServiceUri = new Uri(Site + "/ClientBin/My-Namespace-MyService.svc", UriKind.Absolute);
For item #4, my code looked like:
<param name="source" value="<%= Request.Url.Scheme %>://mytest.blob.core.windows.net/my-container/MySilverlightApp.xap"/>
<param name="enablehtmlaccess" value="true" />
One last thing to note: If using a custom splash screen, then figure out how to get this to work. I don't know how. What I have found out is that if you set splashscreensource as the location of a .xaml file, then it simply does not load. It will just show the basic silverlight load percent screen, which does at least seem to report load % correctly. In order to get the custom splash screen to load, it seems to only work when included inline. You can do this via:
<script id="xamlSplash" type="text/xaml">
<%= System.IO.File.ReadAllText(Context.Server.MapPath("~/Loading.xaml")) %>
</script>
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="splashscreensource" value="#xamlSplash" />
However, while this will show the custom splash screen, it will not work if you have any progress report on the splash screen. The javascript function referenced by onsourcedownloadprogresschanged will never fire. I could not find why this was the case, nor a way around it. You'll just have to have a spinning animation or the like in place of an actual % progress indicator.

What cases will prevent javascript from being executed in a WPF WebBrowser control?

We have a System.Windows.Controls.WebBrowser control rendering HTML with references to jQuery (retrieved with https connection). Our test machine recently had its Internet Explorer version upgraded to 8.0.7600.16385. After the upgrade, the WebBrowser control stopped executing javascript. We tested the same HTML in a regular browser and also in a System.Windows.Forms.WebBrowser control and it works perfectly in both.
Does anybody know what could cause?
It's probably due to security restrictions. Try to include a Mark of the Web on your page. For instance, this comment will tell the WebBrowser to execute the page with the security policy of the Local Intranet zone:
<!-- saved from url=(0016)http://localhost -->
Typically the cause for "JavaScript doesn't execute" is the browser errors while parsing or executing it: file doesn't exist, file has syntax error in it, script threw an exception while running, etc. You've attempted to rule this out by testing in a regular browser, but is there anything in the script that detects a UserAgent or browser features, and fails? Can you harvest console errors from a WPF WebBrowser control?

Get session of DNN in aspx file

I write a standalone aspx file and upload it to DNN website. I add a html module and make an iframe to that aspx file. How I should check DNN user login or not in aspx file? I think there are something in Session but it is empty when I print it out on aspx page.
The aspx file executes outside of DNN. There is no context for you to work with. A much better approach is to turn your .aspx into a .ascx and derive from PortalModuleBase as the start of a DNN module. You can add a proper module to the page and permission the module as you see fit and DNN will take care of all the authentication and authorization details for you.
A starting point for module development
I don't recommend it in this situation, but you can also emulate the approach I described for getting context in a web service.
https://stackoverflow.com/a/9164573/51851
If your aspx is within DNN's website you can simply use Request.IsAuthenticated to check if user is logged in or not.
But be warned, if you have friendly URL turned on - DNN 5x and above will hijack you aspx request.

Resources