minifying signalr hubs auto-generated proxy - signalr

My app is using a SignalR 1.1.2 on ASP.NET MVC
It has the following call in the View
This uses the auto-generated hub.
At this point all client and server side methods are done.
Can I get a copy of the 'hubs.js' file I get when I paste this
link into the browser.
I want to add a new javascript file to the BundleConfig.cs so I
can minify this file and try and improve the performance of my app.
Hope someone can advise, I have done it and it seems to work, I just
want to be sure that I will not loose the ability to shift gears to
websockets, SSE, Forever-Frame depending on what the client and server
can negotiate.

MVC web optimization does not support dynamic scripts. I did it like this in my last project, it doesnt help with minifying but you can add the static script to the bundle config
(function ($) {
var dynamicScripts = ["signalr/hubs", "eventAggregation/events"];
$.each(dynamicScripts, function () {
$.ajax({
url: this,
cache: true,
dataType: "script",
async: false
});
});
} (jQuery));

if you navigate to the /signalr/hubs uri you can save this javascript file and put it in a bundle. Of course if you change anything to do with signalr then it might not work. But this is for release. Just a note that this 1.1.2

Related

The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request

I have a server running asp.net core 3.1 and Vue.
Everything works great but I have one specific page that when I do a http post I get the error
" The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request"
The strange thing is that my server is based off another project that is similar which doesn't have the problem.
I can't see why when I do this http post it is looking for index.html... I dont reference index.html anywhere!
I've looked at previous questions and my config looks fine e.g.
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
the folder name is correct (I saw people had clientApp instead of ClientApp)
The folder is in C:\inetpub\wwwroot so I dont see any problems with that either
I forgot to add HttpPost to one of my APIs so when I did the HTTP post it didn't know where to post it to.
I'm not sure why in my development build it worked though...kinda annoying

Publishing log file to browser in ASP.NET Core

Is there a ready-made solution in ASP.NET Core for publishing log files in browser? This would help developers/testers since they don't always have access to logs on the server. This would of course need to be disabled in production.
I don't believe there are any ready-made tools for this type of request (At least not in any of the documentation I have read).
You could use an AJAX call to the server to retrieve the log file contents and then set them to an HTML element of your choice.
var url = #Url.Action("GetLogFile", "Controller");
$.ajax({
type: "POST",
url: url,
data: logLocation,
success: function(data) {
$(".result").html(data);
}
});​
<div class="result"></div>
Obviously you can use what ever HTML element you want, as a div isn't the best display option. I haven't tested this code but it gives you the idea.
Hope this helps!

IBM SBT :Using Forum API to create discussion forum

How to add the discussion forum in existing application?
Configured with the my application running in WAS and using java snippets i can able to get connected to the connections and get the response .
But with javascript snippets there is a problem .Unable to configure SBT JS and run javascript snippets.
https://localhost:9443/sbt/WebContent/js/sdk/sbt/connections/ForumService is not found
always 404 error in web console.
please help me out
thanks in advance
You should make sure you have the sbt.web project on your server. It sounds like the ForumsService dojo file isn't found.
Also make sure that your managed-beans.xml file is configured, and set properly to point to your connections server.
Here is a snippet which shows the path invocation for ForumService. You can see many more examples in the GitHub Project and reference the wiki which describes your first JS App http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=SDK+docs#action=openDocument&res_title=Adding_the_SDK_to_your_web_application_SDK1.0&content=sdkcontent
require(["sbt/connections/ForumService", "sbt/dom", "sbt/json"],
function(ForumService, dom, json) {
var forumService = new ForumService();
var forumUuid = "%{name=ForumService.forumUuid}";
var promise = forumService.getForum(forumUuid);
promise.then(
function(forum) {
dom.setText("json", json.jsonBeanStringify(forum));
},
function(error) {
dom.setText("json", json.jsonBeanStringify(error));
}
);
}
);

Jboss 7 serving static resources asynchronously

Since Jboss supports Servlet 3.0, servlets can serve in an asynch manner. However, how do i configure jboss or application so that static resources like javascript files, css files and images can be served in an asynchronous manner?
Following link doesn't help either
https://docs.jboss.org/jbossweb/7.0.x/aio.html
Has anyone done this before?
As far as I know and from everything that I have read, Asynchronous support in Servlet 3 does NOT serve web resources. It is used for asynchronously handling HttpServlet Requests and Responses so that your AJAX doesn't get hung up waiting for database connection pooling and the like.
How to asynchronously serve JavaScript and CSS
It is import to place all of your <script> tags/calls at the end of the <body>, right before the </body>. This ensure that your HTML gets loaded before any fetching or running of the scripts happen.
The simplest way to serve JavaScript asynchronously is to use HTML5 and add the 'async' attribute. NOTE: this may only be used for linking JavaScript code with the src attribute, it will not work for JavaScript in the <script> tag.
<script async src="../js/your-javascript-code.js"></script>
If you can not use HTML5 or the async attribute is not supported, you can do the following taken from Thinking Async:
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.src = '//third-party.com/resource.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));
How to asynchronously load CSS using jQuery?
Dynamically loading css file using javascript with callback without jQuery
How to load CSS asynchronously without using JavaScript?
In case you are interested, here is working example of how to use the Servlet 3 asynchronous feature, demonstrating it's intended use, running on JBoss.

Is there a recommended ASP.NET 2.0 method to serve HTML snippets via XHR to the client?

Here is my desired flow:
A static web page (html) uses XHR calls to an ASP.NET page
The .NET page retrieves information from a remote server using web services
The .NET page returns an HTML "snippet" that is inserted into the static HTML page
I'm getting hung up on how to deal with the HTML snippet generation on the .NET (2.0) page. I've thought about something like this in a generic .ashx page:
public void ProcessRequest (HttpContext context)
{
context.Response.Write("<ul>");
//assume "people" is a list of data coming from the external web service
foreach (string person in people)
{
context.Response.Write("<li>" + person + "</li>");
}
context.Response.Write("</ul>");
}
It just seems a big "ugly". Has anyone done this another - and possibly more efficient/elegant - way? Any help would be appreciated.
Returning html for this task is a bit weird, IMO. In most times I prefer the following way. Open your web service to public or add a wrapper to it and just use it directly from js of your static page. The service should return json (preferable) or xml data. On the client side format (print in html as you want) received data using js in callback to the XHR and inject anywhere you want.
But also I want to cast YAGNI on this task - if it'll be used only several times and in a few pages, use the most fastest way to implement it. But if you are building some RIA application I recommend you to check ExtJS javascript library.
Edit 26/02:
If you can't use ASP.NET MVC but wanna to use some good framework instead of "Response.Write" stuff please check OpenRasta. It's one of my favorite web frameworks. It works fine on .Net 2.0 and it's very flexible and powerful. And also it has a great community.

Resources