{"id":19101591,"url":"https://github.com/MicrosoftEdge/pushnotifications-demo-aspnetcore","last_synced_at":"2025-04-18T18:32:42.024Z","repository":{"id":40918255,"uuid":"150454619","full_name":"MicrosoftEdge/pushnotifications-demo-aspnetcore","owner":"MicrosoftEdge","description":"Demo for cross-browser push notifications with ASP.NET Core server side code","archived":false,"fork":false,"pushed_at":"2022-12-08T01:29:28.000Z","size":795,"stargazers_count":46,"open_issues_count":4,"forks_count":20,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-04-14T03:59:59.626Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MicrosoftEdge.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-26T16:11:41.000Z","updated_at":"2024-01-31T05:30:10.000Z","dependencies_parsed_at":"2023-01-24T14:01:20.529Z","dependency_job_id":null,"html_url":"https://github.com/MicrosoftEdge/pushnotifications-demo-aspnetcore","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftEdge%2Fpushnotifications-demo-aspnetcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftEdge%2Fpushnotifications-demo-aspnetcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftEdge%2Fpushnotifications-demo-aspnetcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MicrosoftEdge%2Fpushnotifications-demo-aspnetcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MicrosoftEdge","download_url":"https://codeload.github.com/MicrosoftEdge/pushnotifications-demo-aspnetcore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783095,"owners_count":17201908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T03:53:22.093Z","updated_at":"2025-04-18T18:32:41.994Z","avatar_url":"https://github.com/MicrosoftEdge.png","language":"C#","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# Web Push Notifications Tutorial\n\nThis is a tutorial and demo for web push notifications that work in modern web browsers. Frontend is written in vanilla JavaScript, while the backend is using the ASP.NET Core 2.1 framework.\n\n\u003e If you are searching the node.js version of this sample, you can find it [here](https://github.com/MicrosoftEdge/pushnotifications-demo).\n\n## How to use\n\nFirst, install all .NET dependencies via `dotnet restore`.\n\nThis demo uses an in-memory SQL database instance for storing push subscription info to send push updates at some other point in time. It also requires specifying a public and private key for identifying your server to the push service's server. These keys, known as VAPID public/private keys, can be generated and printed to the console when first executing the site. The site can be executed by running `dotnet run` which will start a server on `https://localhost:5001`. You'll need to populate those keys as environment variables and execute `dotnet run` again to ensure that push messages can be configured from your server.\n\nYou should set the environment variables mentioned above in your `appsettings.json` file as follows:\n\n```json\n{\n  \"Vapid\": {\n    \"Subject\": \"mailto:email@outlook.com\",\n    \"PublicKey\": \"YOUR_PUBLIC_KEY\",\n    \"PrivateKey\": \"YOUR_PRIVATE_KEY\"\n  },\n  \"ConnectionStrings\": {\n    \"Database\": \"Server=(localdb)\\\\mssqllocaldb;Database=PushDemoInMemoryDb;Trusted_Connection=True;ConnectRetryCount=0\"\n  },\n  \"Logging\": {\n    \"LogLevel\": {\n      \"Default\": \"Warning\"\n    }\n  },\n  \"AllowedHosts\": \"*\"\n}\n```\n\n## Key components of the sample\n\nThe following files contain code that's related to generating VAPID keys, registering a push subscription and sending push notifications.\n\n### ASP.NET Core backend\n\n- [`appsettings.json`](/PushnotificationsDemo/appsettings.json) Contains VAPID keys and the database connection string.\n- [`Startup.cs`](/PushnotificationsDemo/Startup.cs) Configures the app and the services it uses, including the database connection.\n- [`PushController.cs`](/PushnotificationsDemo/Controllers/PushController.cs) Contains the API endpoints.\n- [`PushService.cs`](/PushnotificationsDemo/Services/PushService.cs) Contains the Push service which is used to manage saving subscriptions to the database and sending push notifications.\n\n### Frontend\n\n- [`Index.cshtml`](/PushnotificationsDemo/Views/Home/Index.cshtml) Contains the sample's UI.\n- [`service-worker.js`](/PushnotificationsDemo/wwwroot/service-worker.js) Contains the sample's service worker which gets registered and will manage the incoming push notifications.\n- [`script.js`](/PushnotificationsDemo/wwwroot/js/script.js) Runs after DOM is loaded and contains methods for service worker and push subscription registration.\n- [`util.js`](/PushnotificationsDemo/wwwroot/js/util.js) Contains methods for push subscription management.\n\n## Running the Azure Function App\n\nThe service which is sending the periodic push notifications (7AM Pacific Standard Time every day) is using Azure Funtions to run periodically. You can run it locally by calling `func host start` in the `PushnotificationsDemoFuntion` folder. You need to create a copy of `settings.json` with the name of `local.settings.json` and fill the VAPID keys.\n\nIf you want to run the Function App more frequently for debugging for example, you can use something like this: `0,15,30,45 * * * * *`. This will run every 15 seconds.\n\n## Contributing\n\nIf you'd like to contribute to this sample, see [CONTRIBUTING.MD](/CONTRIBUTING.md).\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Questions and comments\n\nWe'd love to get your feedback about the Microsoft Graph Connect Sample for ASP.NET Core. You can send your questions and suggestions to us in the [Issues](https://github.com/MicrosoftEdge/pushnotifications-demo-aspnetcore/issues) section of this repository.\n\nQuestions about Microsoft Edge in general should be posted to [Stack Overflow](https://stackoverflow.com/questions/tagged/microsoft-edge). Make sure that your questions or comments are tagged with _[microsoft-edge]_.\n\nYou can suggest changes for Microsoft Edge on [UserVoice](https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer).\n\n## Copyright\n\nCopyright (c) 2018 Microsoft. All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicrosoftEdge%2Fpushnotifications-demo-aspnetcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMicrosoftEdge%2Fpushnotifications-demo-aspnetcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMicrosoftEdge%2Fpushnotifications-demo-aspnetcore/lists"}