在wwwroot中引用静态JavaScript文件时遇到问题-.Net Core 2.2 Signalr [英] Problems referencing static JavaScript files in wwwroot - .Net Core 2.2 Signalr

查看:112
本文介绍了在wwwroot中引用静态JavaScript文件时遇到问题-.Net Core 2.2 Signalr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难从wwwroot文件夹引用与signalr相关的js文件.

I'm having difficulty referencing the relevant js files for signalr from the wwwroot folder.

我需要参考的路径是:

  • wwwroot/lib/@aspnet/signalr/dist/browser/signalr.js
  • wwwroot/js/chat.js

这是我的观点:

@page
<div class="container">
    <div class="row">&nbsp;</div>
    <div class="row">
        <div class="col-6">&nbsp;</div>
        <div class="col-6">
            User..........<input type="text" id="userInput" />
            <br />
            Message...<input type="text" id="messageInput" />
            <input type="button" id="sendButton" value="Send Message" />
        </div>
    </div>
    <div class="row">
        <div class="col-12">
            <hr />
        </div>
    </div>
    <div class="row">
        <div class="col-6">&nbsp;</div>
        <div class="col-6">
            <ul id="messagesList"></ul>
        </div>
    </div>
</div>

<script src="~/wwwroot/lib/@@AspNetCore/signalr/dist/browser/signalr.js"></script>
<script src="~/wwwroot/js/chat.js"></script>

我在浏览器中得到404:

I am getting 404's in the browser:

http://localhost:5005/wwwroot/lib/@AspNetCore/signalr/dist/browser/signalr.js 404(未找到)

http://localhost:5005/wwwroot/lib/@AspNetCore/signalr/dist/browser/signalr.js 404 (Not Found)

http://localhost:5005/wwwroot/js/chat.js net :: ERR_ABORTED 404(不是 找到)

http://localhost:5005/wwwroot/js/chat.js net::ERR_ABORTED 404 (Not Found)

更新

更改脚本路径后,我将在浏览器中遇到以下错误:

After changing my script paths I am faced with these errors in the browser:

http://localhost:5005/lib/@ AspNetCore/signalr/dist/browser/signalr.js net :: ERR_ABORTED 404(未找到)

http://localhost:5005/lib/@AspNetCore/signalr/dist/browser/signalr.js net::ERR_ABORTED 404 (Not Found)

未捕获的ReferenceError:chatR.js:3中未定义signalR

Uncaught ReferenceError: signalR is not defined at chat.js:3

chat.js第3行:

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();

它下面有红色的波浪线.

This has red squiggly lines under it.

推荐答案

我建议您更改文件夹名称并替换这样的网址

I would recommend you change a folder name and replace a url like this

<script src="~/lib/signalr/dist/browser/signalr.js"></script>
<script src="~/js/chat.js"></script>

检查此链接注意:请确保您的代码位于页面底部

Note: make sure your code is place at bottom of the page

这篇关于在wwwroot中引用静态JavaScript文件时遇到问题-.Net Core 2.2 Signalr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆