I created an application with signalR references in visual studio.
Created a hub. When running application on IIS Express, everything works
fine. When I transfer it to IIS8, in firebug I see that URL's of signalR are wrong,
for instance:
http://localhost/signalr/negotiate?connectionData=......
The problem that there is a missing site name, should be:
http://localhost/MYSITE/signalr/negotiate?connectionData=......
This is the script I am using to init connection:
<script type="text/javascript">
var proxy;
$(function () {
var connection = $.hubConnection();
proxy = connection.createHubProxy('chatHub');
proxy.on('newMessage', onNewMessage);
connection.start();
$('#send').click(onSend);
});
function onNewMessage(message) {
$('#messages').append('<li>' + $('#message').val() + '</li>');
}
function onSend() {
proxy.invoke('newMessage', $().val());
}
</script>
I tried to send connection to $.hubConnection(), but then site name is getting doubled:
http://localhost/MYSITE/MYSITE/signalr/negotiate?connectionData=......
Use a tilde to refer to the application root directory when including scripts/other resources. I have a similar setup and this works for me in development and production environments:
<script src="~/Scripts/jquery.signalR-1.1.2.js" type="text/javascript"></script>
<script src="~/signalr/hubs" type="text/javascript"></script>
Related
Blazor serverside (dotnet core 3.1)
I run into the problem that on customer side this is shown:
Could not reconnect to the server. Reload the page to restore functionality.
Each time I update the code base or internet is broken or something like this.
Now the goal is that it should reload the page as soon as the server is back again (or in some interval).
Is there any possibility that could help me?
You can try this code:
<script src="_framework/blazor.server.js"></script>
<script>
Blazor.defaultReconnectionHandler._reconnectCallback = function(d) {
document.location.reload();
}
</script>
<script>
// Wait until a 'reload' button appears
new MutationObserver((mutations, observer) => {
if (document.querySelector('#components-reconnect-modal h5 a')) {
// Now every 10 seconds, see if the server appears to be back, and if so, reload
async function attemptReload() {
await fetch(''); // Check the server really is back
location.reload();
}
observer.disconnect();
attemptReload();
setInterval(attemptReload, 10000);
}
}).observe(document.body, { childList: true, subtree: true });
</script>
This will wait until the reload button appears and then will wait until the server is back up before actually reloading.
From https://github.com/dotnet/aspnetcore/issues/10325#issuecomment-537979717
For .NET 6 & 7 you can use:
<script src="_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start().then(() => {
Blazor.defaultReconnectionHandler._reconnectCallback = function (d) {
document.location.reload();
}
});
</script>
This keeps all of the original startup process as is and just adds a page reload on connection down, without needing a mutations observer.
Here's an alternative but I'm not sure it works 100%.
<script src="~/_framework/blazor.server.js" autostart="false"></script>
<script>
Blazor.start().then(() => {
Blazor.defaultReconnectionHandler._reconnectionDisplay = {
show: () => {},
update: (d) => {},
rejected: (d) => document.location.reload()
};
});
</script>
One trick some people forget about is that you can actually "watch" your code base for changes, if you open your favorite terminal and run dotnet run watch debug in the same folder as your cproj file it should watch your changes so when you refresh your browser it should pick up any changes to your application, formore information read: https://learn.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.1
dotnet watch is a tool that runs a .NET Core CLI command when source files change. For example, a file change can trigger compilation, test execution, or deployment.
Hope this helps
So I've built a site in my directory and it can call all the stylesheets I made up just fine but when I create a local host it posts the html without any of the stylesheet. So the node would look like this
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
});
And my html like this
<head><link href="custome.css" rel="stylesheet"></head>
<body> /snip </body>
So when ever I open up the local host at PORT it's blank.
You should serve static files. You should give more detail about the issue.
If you're using something like express.js, you can do something like this;
const fs = require('fs');
app.get('/custome.css', function (req, res) {
res.send(fs.readFileSync(__dirname+'/custome.css'));
});
Is there a way to render a precompiled template that has no name on the client side in DustJs?
Because documentation only shows with a name:
<!-- precompiled templates -->
<script type="text/javascript" src="/lib/templates.js"></script>
<script type="text/javascript">
// The templates are already registered, so we are ready to render!
dust.render('hello', { world: "Saturn" }, function(err, out) {
document.getElementById('output').textContent = out;
})
</script>
EDIT : Ok it's probably too complicated to load a file, and I just noticed that when we compile without specifying name (in order to compile many template simultaneously), the path of the template is set as the default name. It is even editable with --pwd flag.
There is therefore always a name so the above function can operate.
It sounds like you would like to load templates by their path after they have been precompiled. Dust allows you to do this via AMD (require.js) compatibility.
http://www.dustjs.com/guides/setup/#amd
Once you've loaded require.js and set define.amd.dust = true, you can call dust.render with the path to a template and Dust will automatically load it for you.
Note that this requires that you compile your templates with the --amd flag.
<script src="r.js"></script>
<script type="text/javascript">
define.amd.dust = true;
require(["lib/dust-full"], function(dust) {
dust.render('path/to/your/template', function(err, out) { ... });
});
</script>
The Dust repository has an example of using AMD to load templates.
I have a asp.net mvc app . In Scripts I have the subfolder app containing Controller.js. I also have another subfolder Spec containint ControllerSpec.js - written with jasmine.
describe('PhoneCat controllers', function () {
beforeEach(module('phonecatApp'));
describe('PhoneListCtrl', function () {
it('should create "phones" model with 3 phones', inject(function ($controller) {
var scope = {},
ctrl = $controller('PhoneListCtrl', { $scope: scope });
expect(scope.phones.length).toBe(3);
}));
});
});
In SpecRunner.cshtml i have just included this files:
<script type="text/javascript" src="/Scripts/app/controllers.js"></script>
<script type="text/javascript" src="/Scripts/Spec/controllersSpec.js"></script>
In karma init, I have added the path of those 2.js.
Can you please tell me how can I do to make it work? If I run vs the Jasmine code it's ok.
Thx
You must add a reference to angular.js as well
There could be a variety of reasons for such an error, so it would help to solve with a bit more info on your part.
However off hand and having seen this error before in my battles through angular unit testing, I have to ask are you including a link to angular-mocks.js?
The lastest repo: http://code.angularjs.org/1.2.15/
Angular Mocks: http://code.angularjs.org/1.2.15/angular-mocks.js
A copy of your karma.conf.js would also help....
This is something I have been trying to figure out, but I am not sure exactly how to do it. I have a flex application that logs into facebook, but after that I can't access any of the facebook api. Right now I am using this HTML to log in:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<!-- Include support librarys first -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
//This example uses the javascript sdk to login before embedding the swf
var APP_ID = "[My App ID Here]";
var REDIRECT_URI = "http://apps.facebook.com/isotesthoskins/";
var PERMS = "publish_stream,offline_access"; //comma separated list of extended permissions
function init() {
FB.init({appId:APP_ID, status: true, cookie: true});
FB.getLoginStatus(handleLoginStatus);
}
function handleLoginStatus(response) {
if (response.session) { //Show the SWF
//A 'name' attribute with the same value as the 'id' is REQUIRED for Chrome/Mozilla browsers
swfobject.embedSWF("isotest.swf", "flashContent", "760", "500", "9.0", null, null, null, {name:"flashContent"});
} else { //ask the user to login
var params = window.location.toString().slice(window.location.toString().indexOf('?'));
top.location = 'https://graph.facebook.com/oauth/authorize?client_id='+APP_ID+'&scope='+PERMS+'&redirect_uri='+REDIRECT_URI+params;
}
}
$(init);
</script>
And everything logs in fine, but when I try this in the application after I am logged in, nothing happens.
Facebook.api("/me", function(response){
changeText.text = response.name;
});
I don't need to init because it was done by the javascript login, right? I might be wrong about that though.
Looks like you are calling the API using the Flex SDK.
That is not going to work, as the token is not shared between JS and Flex.
You should login on the Flex side or thunk into the JS to make the call.