Skip to content

Commit cbfed00

Browse files
authored
SignalR Hubs v6.0 (dotnet#3)
1 parent 7e5a495 commit cbfed00

20 files changed

+403
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
##
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
55

6+
Properties/
7+
*.sln
8+
69
# User-specific files
710
*.rsuser
811
*.suo
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.SignalR;
2+
3+
namespace SignalRHubsSample.Hubs;
4+
5+
// <snippet_Class>
6+
public class ChatHub : Hub
7+
{
8+
public async Task SendMessage(string user, string message)
9+
=> await Clients.All.SendAsync("ReceiveMessage", user, message);
10+
}
11+
// </snippet_Class>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@page
2+
@model ErrorModel
3+
@{
4+
ViewData["Title"] = "Error";
5+
}
6+
7+
<h1 class="text-danger">Error.</h1>
8+
<h2 class="text-danger">An error occurred while processing your request.</h2>
9+
10+
@if (Model.ShowRequestId)
11+
{
12+
<p>
13+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
14+
</p>
15+
}
16+
17+
<h3>Development Mode</h3>
18+
<p>
19+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
20+
</p>
21+
<p>
22+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
23+
It can result in displaying sensitive information from exceptions to end users.
24+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
25+
and restarting the app.
26+
</p>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace SignalRHubsSample.Pages;
6+
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
27+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@page
2+
@model IndexModel
3+
4+
@{
5+
ViewData["Title"] = "Home";
6+
}
7+
8+
<div class="form-group row">
9+
<label for="userInput" class="col-2 col-form-label">User</label>
10+
<div class="col col-sm-6">
11+
<input id="userInput" class="form-control" />
12+
</div>
13+
</div>
14+
15+
<div class="form-group row">
16+
<label for="message" class="col-2 col-form-label">Message</label>
17+
<div class="col col-sm-6">
18+
<input id="messageInput" class="form-control" />
19+
</div>
20+
</div>
21+
22+
<button id="send" type="button" class="btn btn-primary">Send Message</button>
23+
24+
<hr>
25+
26+
<ul id="messageList"></ul>
27+
28+
@section Scripts
29+
{
30+
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/6.0.1/signalr.js"></script>
31+
<script src="~/chat.js"></script>
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Mvc.RazorPages;
3+
4+
namespace SignalRHubsSample.Pages;
5+
6+
public class IndexModel : PageModel
7+
{
8+
private readonly ILogger<IndexModel> _logger;
9+
10+
public IndexModel(ILogger<IndexModel> logger)
11+
{
12+
_logger = logger;
13+
}
14+
15+
public void OnGet()
16+
{
17+
18+
}
19+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>@ViewData["Title"] - SignalRHubsSample</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />
8+
<link rel="stylesheet" href="~/site.css" asp-append-version="true" />
9+
<link rel="stylesheet" href="~/SignalRHubsSample.styles.css" asp-append-version="true" />
10+
</head>
11+
<body>
12+
<header>
13+
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
14+
<div class="container">
15+
<a class="navbar-brand" asp-area="" asp-page="/Index">SignalRHubsSample</a>
16+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
17+
aria-expanded="false" aria-label="Toggle navigation">
18+
<span class="navbar-toggler-icon"></span>
19+
</button>
20+
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
21+
<ul class="navbar-nav flex-grow-1">
22+
<li class="nav-item">
23+
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
24+
</li>
25+
</ul>
26+
</div>
27+
</div>
28+
</nav>
29+
</header>
30+
<div class="container">
31+
<main role="main" class="pb-3">
32+
@RenderBody()
33+
</main>
34+
</div>
35+
36+
<footer class="border-top footer text-muted">
37+
<div class="container">
38+
&copy; 2022 - SignalRHubsSample
39+
</div>
40+
</footer>
41+
42+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
43+
44+
@await RenderSectionAsync("Scripts", required: false)
45+
</body>
46+
</html>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
2+
for details on configuring this project to bundle and minify static web assets. */
3+
4+
a.navbar-brand {
5+
white-space: normal;
6+
text-align: center;
7+
word-break: break-all;
8+
}
9+
10+
a {
11+
color: #0077cc;
12+
}
13+
14+
.btn-primary {
15+
color: #fff;
16+
background-color: #1b6ec2;
17+
border-color: #1861ac;
18+
}
19+
20+
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
21+
color: #fff;
22+
background-color: #1b6ec2;
23+
border-color: #1861ac;
24+
}
25+
26+
.border-top {
27+
border-top: 1px solid #e5e5e5;
28+
}
29+
.border-bottom {
30+
border-bottom: 1px solid #e5e5e5;
31+
}
32+
33+
.box-shadow {
34+
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
35+
}
36+
37+
button.accept-policy {
38+
font-size: 1rem;
39+
line-height: inherit;
40+
}
41+
42+
.footer {
43+
position: absolute;
44+
bottom: 0;
45+
width: 100%;
46+
white-space: nowrap;
47+
line-height: 60px;
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@using SignalRHubsSample
2+
@namespace SignalRHubsSample.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
Layout = "_Layout";
3+
}

0 commit comments

Comments
 (0)