How to use xsockets fallback in html file

19 views
Skip to first unread message

priya

unread,
Apr 27, 2015, 2:43:43 AM4/27/15
to xsocke...@googlegroups.com
Hello

How to use fallback in html file. The fallback page is simply working in .cshtml.
I don't want to use with .cshtml file extension. The page should completely run with .html extension. Our clients need all the fallback chat application as html page.
Since we use ASP.NET (c#) without MVC the .cshtml file not working.  Can u pls reply. I'm spending weeks and weeks to solve this issue.
The below code is not running as fallback in .html.

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>XSockets - Simple PubSub With Fallback</title>
</head>
<body>
    <label>Username</label><br />
    <input type="text" id="username" value="Steve" /><br />
    <label>Message</label><br />
    <input type="text" value="Hello World" id="message" /><button id="send">send</button>
    <hr />
    <div data-bind="foreach:messages">
        <div>
            <span data-bind="text:username"></span>: <span data-bind="text:message"></span>
        </div>
    </div>
    <script src="/Scripts/jquery-1.9.0.js"></script>


    <script src="/Scripts/knockout-3.2.0.js"></script>
    <script type="text/javascript">
        //VM
        var vm = { messages: ko.observableArray([]) };
        ko.applyBindings(vm);

        //Connect to the built in "Generic" controller
        var conn = new XSockets.WebSocket('ws://127.0.0.1:9090', ['chat']);
        var controller = conn.controller('chat');

        //Setup a subscription for the topic "chatmessage"
        controller.subscribe('chatmessage', function (d) {
            vm.messages.unshift(d);
        });

        //When button is clicked, publish a chat-message
        document.querySelector("#send").onclick = function () {
            var u = document.querySelector('#username').value;
            var m = document.querySelector('#message').value;
            controller.publish('chatmessage', { username: u, message: m });
        };
    </script>
</body>
</html>

Magnus Thor

unread,
Apr 27, 2015, 4:24:08 AM4/27/15
to xsocke...@googlegroups.com
Hi,

You must ensure that Application_Start event fires , this will "only" occur  when you fetch a ASP.NET resource such as a MVC, ASP.NET WebForm or .ashx file, i also suppose there are more resorces that are threaded as such in the ASP.NET LifeCycle , so.  if you cannot use MVC , for instance a .chtml file (Razor view) as ASP.NET Webform (.ASPX) may be an idea.  Note that the Application__Start will not be fired for each user, only when necessary.  For instance after IIS recycled etc.


Magnus


priya

unread,
Apr 27, 2015, 7:16:18 AM4/27/15
to xsocke...@googlegroups.com
Hi,

Thank u for ur reply. So we can't use fallback in .html file. Im I correct?

Magnus Thor

unread,
Apr 27, 2015, 7:47:28 AM4/27/15
to xsocke...@googlegroups.com
Yes, the fallback works fine from a html file,  But note that XSockets.NET service ( if hosted in IIS ) will require a XSockets Web Boostraper , such the one on startup.cs file of the examples.  And also note that the fallback uses WebAPI to enable fallback, so you will need ASP.NET WebAPI support.   As long as you have that the startup ( Boostraper ) will be called as the fallback actually performs a "server side" call.    So, Yes, you can use an html file,.

Magnus
Reply all
Reply to author
Forward
0 new messages