Detected a connection attempt to an ASP.NET SignalR Server - asp.net-web-api

I have a vuejs application that is created in vue-cli3 and ASP.Net WebAPI w/SignalR created in .Net Framework 4.6.x
I'm having an issue connecting to SignalR and it's throwing an error "Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server".
As per this link: Detected a connection attempt error, i should use signalR instead of #aspnet/signalr. But when i try to use it, now it throws a jquery reference error. Should i really use Jquery here? I'm already stuck for 2 days on this.
My Vue Component:
import { HubConnectionBuilder, LogLevel } from 'signalr'
// import { HubConnectionBuilder, LogLevel } from '#aspnet/signalr' <--- I already tried this,same error
created() {
const connection = new HubConnectionBuilder()
.withUrl('https://localhost:44356/chat-hub')
.configureLogging(LogLevel.Information)
.build()
connection.start()
}
My Startup.cs
public void Configuration(IAppBuilder app)
{
app.Map("/chat-hub",
x =>
{
x.UseCors(CorsOptions.AllowAll);
var hubConfig = new HubConfiguration
{
};
x.RunSignalR(hubConfig);
}
);
app.MapSignalR();
}

The problem is that you have used the ASP.NET Server component and the .NET Core Client.
You cannot mix those as they are not compatible.
Since you are building on .Net Framework 4.6.x and have the ASP.NET Server you need to download the ASP.NET Client which yes, does require JQuery.
If you don't want to use JQuery you will need to do the opposite and replace your server component with .NET Core 3.1 and keep (update) to the same .NET Core Client. Be aware that this is not a simple replacement, you will need to update many aspects of your code.

Related

Matblazor throws an exception in my WebAssembly project in .NET 6

I have used Matblazor succesfully in a .Net blazor server project in .NET 5.
But my new project is now a Webassembly and is running on .NET 6.
I followed all the instructions in the Matblazor home page site, but I have this client side error:
Could not find matBlazor.matButton.init (matbalzor was undefined)
you should modify your program.cs like this
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using WareHoseManagement.Client;//this is my application so you should write here yours
using MatBlazor;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddMatBlazor();
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
await builder.Build().RunAsync();

SSRS reports with .Net Core 3.1 MVC application

I am trying to display the SSRS report in a .Net Core 3.1 MVC application.
I tried to implement the approach mentioned in
https://alanjuden.com/2016/11/10/mvc-net-core-report-viewer/?unapproved=58532&moderation-hash=321d5350c96d2fcf83baa4c939bbdf53#comment-58532
public class ReportsController : AlanJuden.MvcReportViewer.ReportController
{
protected override ICredentials NetworkCredentials
{
get
{
//Custom Domain authentication (be sure to pull the info from a config file)
return new System.Net.NetworkCredential("username", "password");
//Default domain credentials (windows authentication)
//return System.Net.CredentialCache.DefaultNetworkCredentials;
}
}
protected override string ReportServerUrl
{
get
{
//You don't want to put the full API path here, just the path to the report server's ReportServer directory that it creates (you should be able to access this path from your browser:
return "https://YourReportServerUrl.com/ReportServer/ReportExecution2005.asmx";
}
}
public IActionResult ProcessReport()
{
var model = this.GetReportViewerModel(Request);
model.ReportPath = "reportPath";
return RedirectToAction("ReportViewer", model);
}}
but it is not working with the latest framework.
I am getting following error while running the project - Error screenshot
Any help is appreciated.
Thanks!
The same thing happened to me, in my case I needed to install the same package that tells you to install
Install-Package System.ServiceModel.Http -Version 4.1.0
or in the nuget look for the package System.ServiceModel.Http
I tried different workarounds with latest .NET Core including the one you mentioned from Alan Juden. However the easiest thing that worked for me is to create a plain .NET WebForms site using the Report Viewer control from Microsoft. It was still a lot of code but this is solid because the Report Viewer control has been around for many years.
In my case it is showing SSRS Report from Angular UI, but the same will work with MVC or any other Web UI because you will actually redirect/navigate to another url (WebForms aspx page).
More details here.

Connecting to Event Hub

In my code below I am attempting to create a producer client that i can use to send events to a Event Hub. I am getting a System.PlatformNotSupportedException: 'The WebSocket protocol is not supported on this platform. error Any guidance on how i can resolve this would be much appreciated. FYI my platform is Windows 7, although this program is intended to run on a windows 2008 server or later.
var producerOptions = new EventHubProducerClientOptions
{
ConnectionOptions = new EventHubConnectionOptions
{
TransportType = EventHubsTransportType.AmqpWebSockets,
},
RetryOptions = new EventHubsRetryOptions
{
MaximumRetries = 5,
TryTimeout = TimeSpan.FromMinutes(1)
}
};
var producer = new EventHubProducerClient(connectionString, eventHubName, producerOptions);
//here is where the error occurs. which is inside a try - catch block
var eventBatch = await producer.CreateBatchAsync();
......
The Event Hubs client library relies on the underlying framework for its transport communication. In this case, it sounds as if you're using the full .NET Framework on Windows 7, where web sockets is not supported.
So long as your aren't using a UWP application, changing the target framework to .NET Core and using the netstandard2.0 target from the client library may work. (see: this PR)
More detail can be found in the accepted answer for this question, which also contains some advice for third party packages that may work as a polyfill.

Deploy ASP.net core 2.1 WEB API to IIS using Visual Studio Code

Working on an ASP.net core 2.1 web API project. I need to enable the API so that it can be accesed by client applications that we also have under developement.
So far, the only way I've found to publish to IIS is by doing a manual process:
Run dotnet publish -c Release
Copy the files in bin\Release\netcoreapp2.1\publish\ to my IIS Web App folder
I wonder if there is a more straight forward way of doing this.
Also It takes quite sometime to build this release, so for a development environment it's quite a slow process. The problem is that we cannot allow external access to the WEB api when running with F5 on the Integrated test server. How can we enable an more agile testing environment?
Another issue is that when calling for example fetch('MyAPIServer/api/MyItems') from a javascript application, I get a CORS error:
Failed to load http://localhost:86/api/shit: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8082' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
Is enabling CORS absolutely necesary when developing this type of apps?
If I fetch like this:
fetch(
`http://localhost:86/api/shit`,{mode: 'no-cors'}
)
I get:
Uncaught (in promise) SyntaxError: Unexpected end of input
at eval (Pos.vue?7f37:68)
As far as the CORs issue goes you can add the following to your startup:
public void ConfigureServices(IServiceCollection services)
{
// Rest of config stuff ...
services.AddCors();
}
Then in you will also need to add the following.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(builder =>
{
builder.WithOrigins("http://localhost:8080",
"http://localhost:8081",
"http://localhost:8082")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();
});
app.UseMvc();
}

how to upload a file to asp.net core backend with http

Now I use Asp.net core as the server framework. I want to know how to upload a file to an Asp.net core server? I use web api but not the web application. So form submit is no use. The code below doesn't work.
[HttpPost("uploadImage/{accountGuid}")]
public async Task<string> UploadTargetImage(ICollection<IFormFile> files,Guid accountGuid)
{
if (files == null) throw new Exception("File is null");
if (files.Count == 0) throw new Exception("File is empty");
}
I use fiddler to test the API. Like below:
see the fiddler post image
The result of api is File is empty.So the server didn't get the post file.
What should I do? It puzzles me for a long time.
I hava just fix it! The input name in POST must be the same as method param in ASP.NET.

Resources