在项目上右击 -> 添加 -> 添加客户端库 a. 提供程序选择unpkg b. 库输入@aspnet/signalr@1.1.4 c. 选中选择特定文件 d. 勾选signalr.js、signalr.js.map、signalr.min.js和signalr.min.js.map e. 目标位置改为wwwroot/js/
在项目上右击 -> 添加 -> 添加客户端库 a. 提供程序选择cdnjs b. 库输入vue@2.6.14 c. 选中选择特定文件 d. 勾选vue.js和vue.min.js e. 目标位置改为wwwroot/js/
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options => options.AddPolicy("CorsPolicy",
builder =>
{
builder.AllowAnyMethod().AllowAnyHeader()
.AllowCredentials();
}));
services.AddSignalR();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// 允许跨域请求及使用静态文件作为请求路径服务
app.UseHttpsRedirection()
.UseDefaultFiles()
.UseCors("CorsPolicy")
.UseSignalR(route =>
{
route.MapHub<ChatHub>("/chathub");
}).UseStaticFiles();
//app.Run(async (context) =>
//{
// await context.Response.WriteAsync("Hello World!");
//});
}
}
创建ASP.NET Core Web应用程序的空项目模板(SDK版本.NET Core -> ASP.NET Core2.1)在项目StartUp类内容修改如下:public class Startup{ // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configu.