SignalR basic sample issues - c#

I'm trying to follow the SignalR quickstart sample, but I can't get it to work.
Firstly I'm not quite sure where to place the chat.cs hub file in a MVC project - I have tried a few places, but suspect this is where I'm going wrong. It's currently sitting in a folder called signalr in the project root.
The javascript error I'm getting is as follows:
GET http://localhost:50109/signalr/hubs 404 (Not Found)
I added the signalr nuget package, so I think I should have everything I need!
Thanks for reading

Ah, found the following in the FAQ
Why does signalr/hubs return 404 or Why do I get 'myhub' is undefined?
First, make sure you have a call to MapHubs() in Global.asax
RouteTable.Routes.MapHubs();
I also had to remove the following from my global.asax:
BundleConfig.RegisterBundles(BundleTable.Bundles);
Guess I need to spend some time re-jigging my bundles so to say.

Related

BIM 360 REST Endpoints problems

we actually started with the BIM360 API at work. We implemented most of the enpoints that are provided by the API # https://developer.autodesk.com/en/docs/bim360/v1/reference/http/
At one point I have discovered some issues.
After succesfully creating a project with the API it needs to be activated. With first response which tells the project was created under an specific ID.
Taking this ID and creating a new Request I get the following response:
"{\"code\":1001,\"message\":\"You cannot change the status of a project that has no project admin.\"}"
OK no problem I think and create a new Request to patch the Project with an project admin. But there I get following message:
{\"code\":1004,\"message\":\"this project doesn't exist.\"}"
#https://developer.api.autodesk.com/hq/v1/accounts/:account_id/projects/:project_id/users
The things thats make me curious is that the Projects exist as Response from Get Project and is visible in the WEB Interface from Autodesk.
I tried to add an project admin with API again, but took a Project that was created from the Autodesk BIM 360 Webinterface. And it works, because it is activated automatically.
At this point I can't find a solution which it get working...
(Side note we using C#, the actual Autodesk API, RestSharp, Newton Json...)
Maybe someone else got it working?
Thanks for your time!
There is a tutorial:
https://developer.autodesk.com/en/docs/bim360/v1/tutorials/activate-service/
Could you try that?
We had a similar question before and verified it works:
Autodesk Forge BIM 360 API - Activating Service Types

Is there a way in Visual Studio to configure the default start page for web deployment starting from Empty ASP.NET Web App?

Entry level web developer here, thank you in advance.
A very basic single page website starting from Empty ASP.NET Web Application adding each and folder file from scratch. Everything works fine locally bare bones. I'm trying to configure the start page in the subfolder "html" to the file index.html. I get the default "This website has been successfully created" after publishing. Azure web service is working fine because I can go to site.azurewebsites.net/html/index.html to see my page after it's published.
Right clicking the project and going to properties to set as start page, or going to Properties>Specific Page doesn't work as suggested here for deployment but works fine locally. Altering the web.config file as suggested here gives me an internal server error that is fixed once I remove the code
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="html/index.html"/>
</files>
</defaultDocument>
</system.webServer>
I tried different variations of this all with the same internal server error. Is my syntax correct?
I then created a global.asax file and changed the Application_Start line as suggested here:
protected void Application_Start(object sender, EventArgs e)
{
Response.Redirect("/HTML/index.html");
}
Same result.
Lastly, I created an App_Code folder with a RedirectHandler.cs file as suggested by Rion Williams's last suggestion (first link) along with his code and sure enough I get the same result.
"This web app has been successfully created" after publish but I see my desired start page after adding /html/index.html to the end of the url.
Understanding how basic this problem is I took extra care to exhaust as many google searches as I could find relating to the topic before asking this question. My first question on StackO so my reputation is too low to link each page I found. My next attempt is to just start a brand new MVC project and painstakingly rearrange every single file that way. I'm confident that will work but I didn't want to leave this simpler method without learning from what I did wrong especially when I know the answer is going to derp-slap me in the face.
Have you tried to configure the default document under the configuration tab for your website in Azure portal?
With a lot of changing file locations around, clearing cache, and rebooting to avoid server and runtime errors, #hernandgr had the simple option I hadn't known about (shame on me) and funny enough couldn't successfully google about.
It turns out that I didn't need to do any of the steps I had tried to configure the start page beyond just changing it in the configuration tab in the Azure Management Portal. I deleted the global.asax file and the App_Code folder completely, didn't need to touch the web.config in any way and didn't need to implement MVC.
One thing to be noted was that making index.html my start page through Azure seemed to push it up a directory so my CSS, JS, LESS, fonts, and images folders had to be moved up as well to display the page properly.

Could someone explain how this ignore route works?

So I added an ASMX web service to my MVC4 but when I tried to access it I got a "The Resource could not be found" error. After searching I found the answer here.
In short, I had to add the following IgnoreRoute to my RouteConfig file.
routes.IgnoreRoute("{*x}", new { x = #".*\.asmx(/.*)?" });
I understand the MapRoute function in MVC fairly well, however the IgnoreRoute, not so much. I understand that it's targeting the .asmx postfix but I'm not sure on the how's and why's of this quick fix.
How does this IgnoreRoute work, and exactly why does it make my MVC app magically understand how to find and execute my web service? BTW, My only mapped route, currently, is the default, but is there another/better way of solving this issue using MapRoute or another fix?
ignore route indicates that routing should ignore these requests and ASP.NET processing of these requests will occur.
http://haacked.com/archive/2008/07/14/make-routing-ignore-requests-for-a-file-extension.aspx/

SignalR calling client method from outside hub using GlobalHost.ConnectionManager.GetHubContext doesn't work. But calling from within the hub does

I'm trying to call a client method from within a .net Web API controller action.
Can I do this?
The only post I can find that comes close to what I am looking to do is this one:
SignalR + posting a message to a Hub via an action method
In there a message is sent from within an asp.net MVC controller action using GlobalHost.ConnectionManager.GetHubContext.
When I try that inside my Web API action no errors are thrown, but the method "methodInJavascript" is never invoked on the client side.
Public ActionResult MyControllerMethod()
{
var context = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
context.Clients.All.methodInJavascript("hello world");
// or
context.Clients.Group("groupname").methodInJavascript("hello world");
}
When I set a break point inside that action, I see that the code is being reached and executed. Nothing happens on the javascript client side though.
Why? Is Web API so different under the hood that this won't work? Has anyone else tried it and had success?
When I call the "methodInJavascript" from "within" my hub, it works perfectly. Just won't work when called from within a .net Web API controller action.
UPDATE:
After researching this issue I have no solution. I can only assume there is something missing from examples like this Server to client messages not going through with SignalR in ASP.NET MVC 4 and this calling SignalR hub from WebAPI controller issues like maybe there is an additional configuration step to enable calling from a HubContext or something. The code I initially posted here is like that which appears in those examples has not been demonstrated to be flawed in any way. Can anyone see a flaw in the code? Calling from html works. I do it extensively in my apps and never experience an issue. I have never seen a call from the HubContext in an API controller work. No errors. Just no results on the client.
SOLVED (kind of):
Code above does indeed work as is when published. Does not work in Visual Studio dev environment via localhost though. No errors but no result on the client end. Publishing the code as is to a real server on the web does indeed work. I never thought there'd be a difference so I never tried. Figured if it didn't work locally it wouldn't work published. It's working live now but I'm wondering why it doesn't work via localhost in the dev environment. Can't test locally with breakpoints and such.
I have a feeling it's that signalr virtual directory. Something is different when run locally vs published. Not sure what but I see lots of posts like http://www.bitwisejourneys.com/signalr-hosting-in-iis-a-nasty-gotcha/. Reading now to see if there's a way to have it work both locally and published.
I came across with same issue couple days ago. That took my 2 days to find solution and resolve it. After some serious investigate the problems root cause was the signalr dependency resolver that I set customly.
At the end I found this link and that was saying this:
Replacing the DependencyResolver
You can change the DependencyResolver to use your DI container of
choice by setting GlobalHost.DependencyResolver.
NOTE: DO NOT override the global resolver in PreApplicationStart, it
will not work, or it'll work only sometimes. Do it in
PostApplicationStart (using WebActivator) or in Global.asax.
The important place here the NOTE. Of course after signalr 2.0 this documentation become deprecated. So I mixed some of here with the new SignalR API. In new SignalR API not using WebActivatorEx anymore. OwinStartup preferred instead of WebActivator.
[assembly: OwinStartupAttribute(typeof(YourNamespace.Startup))]
namespace YourNamespace
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
//IoC container registration process
UnityConfig.RegisterComponents();
UnityConfig.Container.RegisterType<AHub, AHub>();
HubConfiguration config = new HubConfiguration();
config.EnableJavaScriptProxies = true;
//You should remove your dependency resolver code from here to Global.asax Application_Start method. Before setting the MVC properties.
//config.Resolver = new SignalrDefaultDependencyResolver(UnityConfig.Container); // your dependency resolver
//
app.MapSignalR(config);
}
}
}
And in your global.asax
namespace YourNamespace
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
//Here your SignalR dependency resolver
GlobalHost.DependencyResolver = new SignalrDefaultDependencyResolver(UnityConfig.Container);
//other settings goes on
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
I dont want to send all the code here, for showing up the real problem.
So for me everything works fine for now. Dependency injection also works too. But the bad part is everywhere that I searched David Fowler was saying "Its by design". I started to think is this design really a necessary or a mistake.
Hope it helps somebody else who makes research for same problem.
I had the same issue, and it is related to IoC (with whatever such as ninject or castle).
If you set the global dependency resolver to your IoC manager, it will also replace the SignalR inner pipeline resolution. This makes your SingleTon client hub, not work correctly.
I solved it by only having the Server Hubs being IoC-ed
The code below requires SignalHubActivator (you can find it on the internet)
Now, GlobalHost.ConnectionManager.GetHubContext will return the single instance AND client methods will be called correctly again!
//configuration.Resolver = signalrDependency ; dont, this will cause GlobalHost.ConnectionManager to be intercepted by Castle
configuration.Resolver.Register(typeof(IHubActivator),
() => new SignalHubActivator(container));

Why does DotNetNuke log me out on post ajax requests?

Previously, when I tried to do an ajax call to an ashx as a non-superuser account (i.e. as portal specific user) my web server would return cookies to clear my authorization. I posted a question about this and it seemed the answer was to make sure that the portalid=xx was specified in my GET parameters.
However, I have just found out that if I add portalid=xx in a POST request, DotNetNuke seems to ignore and and log out any non-superuser account.
How can I keep authorization during DNN POST ajax requests?
I think I have a good handle on the whole situation, and unfortunately it appears that the only true solution is to make sure each child portal has its own subdomain rather than a sub-url (e.g. portal.domain.com rather than domain.com/portal).
The problem is that when your portal 0 is domain.com but portal 1 is domain.com/portal everything works correctly until you need to access an .ashx file via ajax. What happens then is the URL that's requested is instead domain.com/DesktopModules/MyModule/Handler.ashx, which does not contain the /portal/ in it, thus causing DNN to think you are doing a request on portal 0 and logging you out.
While GET requests can overcome this with a portal=1 parameter, this does not seem to work for POST requests.
Therefore, the best solution it seems is to have your portal on a distinct subdomain (portal.domain.com), and then you don't risk missing something like this.
I've found a few things for you to check out and see if any of them solve your problem.
Make sure you are using a ScriptManagerProxy. This allows ascx pages to use AJAX while the parent page is also using AJAX.
There have been many reports of people not being able to run AJAX with DNN if Page State Persistence is set to "Memory". Those who experience this have been able to fix it by switching Page State Persistence to "Page". The easiest way to do this is to run this query:
update HostSettings
set SettingValue='P'
where SettingName='PageStatePersister'
After you run that, you'll need to recycle the application. If you don't have access to the server, just add a space or carriage return to your web.config file (that will force the app to recycle).
Lastly, you might see if you have this line in your web.config. Sometimes removing it will help:
<system.web>
<xhtmlConformance mode="Legacy" />
</system.web>

Categories