(C#)SignalR 2.2.2 - 项目从VS(2017年以下)转移到VS 2017的问题

问题描述 投票:1回答:1

事实证明,微软提供了如何制作聊天的Web应用程序的教程,可以在这里找到:https://docs.microsoft.com/en-us/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr#setup

设置似乎非常简单,但是当涉及哪个版本的代码与最新更新兼容时,这个设置很棘手。我要提到的一件事就是提示弹出要求用户输入他们的名字。为了做到这一点,我用以下代码替换了给定的HTML代码:

<title>SignalR Simple Chat</title>

<style type="text/css">

    .container {
        background-color: #99CCFF;
        border: thick solid #808080;
        padding: 20px;
        margin: 20px;
    }
</style>

<div class="container">

    <input type="text" id="message" />

    <input type="button" id="sendmessage" value="Send" />

    <input type="hidden" id="displayname" />

    <ul id="discussion"></ul>

</div>

<script src="scripts/jquery-1.6.4.js"></script>

<script src="scripts/jquery.signalR-2.2.2.js"></script>



<!--Add script to update the page and send messages.-->

<script type="text/javascript">

    $(function () {



        var connection = $.hubConnection();

        var chat = connection.createHubProxy('chatHub');

        // Declare a proxy to reference the hub.

        //var chat = $.connection.chatHub;

        // Create a function that the hub can call to broadcast messages.

        chat.on('broadcastMessage', function (name, message) {

            // Html encode display name and message.

            var encodedName = $('<div />').text(name).html();

            var encodedMsg = $('<div />').text(message).html();

            // Add the message to the page.

            $('#discussion').append('<li><strong>' + encodedName

                + '</strong>:  ' + encodedMsg + '</li>');

        });

        // Get the user name and store it to prepend to messages.

        $('#displayname').val(prompt('Enter your name:', ''));

        // Set initial focus to message input box.

        $('#message').focus();



        connection.start(function () {

            $('#sendmessage').click(function () {

                // Call the Send method on the hub.



                chat.invoke('Send', $('#displayname').val(), $('#message').val());

                // Clear text box and reset focus for next comment.

                $('#message').val('').focus();

            });



        });

    });

</script>

就弹出窗口而言,这似乎做了适当的事情。但是,只要在显示框上看到用户的实际输出,按下发送按钮时就看不到任何内容。此外,新的HTML代码似乎允许VS 2017程序员在单击“发送”按钮时清除聊天框。任何人都可以在这个简单的应用程序中找到可能不是最新的东西吗?

这可能是SignalR的更新问题或其他问题......

c# asp.net-mvc web-applications visual-studio-2017 signalr
1个回答
1
投票

我不知道这是否是你的情况,如果我的答案将解决你的问题,但似乎在VS 2017中创建的项目在他们的csproj文件中包含以下说明:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

在遇到类似错误后,一旦我手动将上述说明添加到我现有的csproj文件中,我的项目最终设法加载到VS 2017

要进一步详细说明,请在csproj文件中找到以下文本(该文件定义了Web应用程序目标的导入):

<Import Project="$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets" Condition="'$(VSToolsPath)' != ''" />

并在它之前放置说明。

© www.soinside.com 2019 - 2024. All rights reserved.