title: Asp Net Core Web Push Notifications
body: <p>Main goal is to add to site ability to send web notification to pop up a system notification to alert the user using Html5 Push API and service workers.
  Not using SignalR which only can run client scripts while site is opened. Also should be ability to send notification if site is closed, as mentioned <a href="https://stackoverflow.com/a/27256165/1235390">here</a> - it is possible.</p>
  
  <p><a href="https://developer.mozilla.org/ru/docs/Web/API/Push_API/Using_the_Push_API" rel="noreferrer">Here</a> is good article about Push API and provided good <a href="https://github.com/chrisdavidmills/push-api-demo" rel="noreferrer">example</a>
  But it uses NodeJS as server and <a href="https://github.com/web-push-libs/web-push" rel="noreferrer">web-push</a> component to send requests to notification services. </p>
  
  <p>Can't find any .NET examples. I think about the two workarounds. </p>
  
  <p>First, is to write everything from scratch based on Push API article <a href="https://developer.mozilla.org/ru/docs/Web/API/Push_API/Using_the_Push_API#The_server" rel="noreferrer">note</a> about server: </p>
  
  <blockquote>
    <p>When you send a push message without data, you simply send it to the endpoint URL using an HTTP POST request. However, when the push message contains data, you need to encrypt it, which is quite a complex process.</p>
  </blockquote>
  
  <p>Second, is to use AspNetCore.NodeServices (<a href="http://blog.nbellocam.me/2016/08/24/javascriptservices-asp-net-core/" rel="noreferrer">article</a> about it) to execute node.js script file</p>
  
  <p>Are there more solutions? Maybe exists ready solution for this?</p>
  
  <p><strong>After subject researching</strong></p>
  
  <p>3 cases:</p>
  
  <ol>
  <li>HTTP + old browsers + IE all versions - Use SignalR + render Notification using html+js</li>
  <li>HTTP + Modern browsers (Chrome, Firefox, Safary, Opera?, Edge) with support of Notification API. - Use SignalR and trigger native browser notification with js using <code>new Notification('Message')</code></li>
  <li>HTTPS + Chrome (Mobile) with support of Push API to trigger native notification for closed site using service-workers. Mobile version of Chrome can create notifications only by using service-worker.</li>
  </ol>
  
  <p>It's became to complicated. What is wrong? </p>
  
  <p><strong>Possible solutions:</strong></p>
  
  <p>For 1 and 2 cases found <a href="https://sciactive.github.io/pnotify/#demos-modules" rel="noreferrer">this</a> repository. Think it is a good frontend solution with a good fallback support. 
  For 3 case still don't know what to do. </p>
  
  <p><strong>Current solution. Added: 2017-11-22</strong></p>
  
  <ul>
  <li>No offline clients notifications support</li>
  <li>No mobile support</li>
  <li>For Chrome v62+ moving all project to <strong>https</strong> - <a href="https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins" rel="noreferrer">link</a></li>
  <li>Using SignalR (0.2.0) for sending push to online clients</li>
  <li>Using <a href="https://github.com/sciactive/pnotify" rel="noreferrer">pnotify</a> v3+ to show native desctop or html notifications.</li>
  <li>Waiting for <a href="https://github.com/sciactive/pnotify" rel="noreferrer">pnotify</a> v4.0.0 (author promises chrome mobile support. <a href="https://github.com/sciactive/pnotify/issues/288" rel="noreferrer">Issue</a>)</li>
  <li>Waiting for .NET Core 2.1 with SignalR 1.0 to rewrite whole project to it.</li>
  </ul>