title: Cannot Read Property Undefined
body: <p>I have created an endpoint in my .NET Core MVC project.</p>
  
  <p>My Api is:</p>
  
  <pre><code>[HttpGet("/api/notifications")]
  public async Task&lt;IActionResult&gt; Notifications()
  {
        var user = await GetCurrentUserAsync(); // Gets the current logged user.
  
        if (user == null)
              return StatusCode(401);
  
        var notifications = _notificationService.GetUserNotifications(user.Id);
  
        var serialized = JsonConvert.SerializeObject(notifications);
  
        return Ok(serialized);
  }
  </code></pre>
  
  <p>And I'm using SignalR for <strong>Database Change Notifications</strong></p>
  
  <pre><code>[HttpPost]
  public async Task&lt;IActionResult&gt; CreateNotification(NotificationModel model)
  {
      var notification = new Notification()
      {
            NotificationTitle = model.NotificationTitle,
            NotificationBody = model.NotificationBody,
            DateTime = DateTime.UtcNow
      };
  
      _notificationService.Create(notification);
  
      // Many to many relationship between Notifications and Users
      // Many to Many table looks like =&gt; NotificationId | UserId | isRead
      // So in this action, because of the notification is created for the first time, 
      // NotifyUsers method will set 'isRead' property to false.
      _notificationService.NotifyUsers(notification, model.userIds);
  
      //Here Notify the Clients with SignalR!
      await _notificationHubContext.Clients.All.SendAsync("initSignal", "message");
  
      return RedirectToAction("PublishedNotification", "Portal");
  
   }
  </code></pre>
  
  <p>and at last, I have a Javascript file where I'm controlling the data comes from api with SignalR.</p>
  
  <p><strong>notification.js</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>window.onload = () =&gt; notifyUser();
  
  var connection = new signalR.HubConnectionBuilder().withUrl("/NotificationHub").build();
  
  connection.on("initSignal", () =&gt; notifyUser());
  
  connection.start().catch(function (err) {
      return console.error(err.toString());
  });
  
  const endPoint = "http://{my-site}.com/api/notifications";
  
  async function getNotifications() {
      try {
          var response = await fetch(endPoint);
  
          var notifications = await response.json();
  
          // Filters notifications where isRead properties are "false"
          var unreadNotifications = notifications.filter(notification =&gt; !notification.isRead);
  
          return { notifications, unreadNotifications };
      } catch (e) {
          console.error(e);
      }
  }
  
  function notifyUser() {
      var ul = document.getElementById("notification-list");
      ul.innerHTML = "";
      var notificationDropdownBtn = document.getElementById("notification-dropdown");    
      var initialNotificationLimit = 2;
  
      notificationDropdownBtn.onclick = () =&gt; {
          notifyUser();
      }
  
      getNotifications().then(notifications =&gt; {
          let { unreadNotifications = [] } = notifications;
  
          if (unreadNotifications.length &gt; 0) {
  
              var notificationControl = document.getElementById("notification-control");
  
              notificationControl.textContent = unreadNotifications.length;
  
              unreadNotifications.forEach((notification, index) =&gt; {
                  if (index &gt; initialNotificationLimit) {
                      return;
                  }
                  ul.insertAdjacentHTML("beforeend", (createNotificationListItem(notification)));                
              });
  
              var loadBtn = document.getElementById("load-more");
              loadBtn.onclick = () =&gt; {
                  ul.innerHTML = "";
                  initialNotificationLimit += 3;
                  unreadNotifications.slice(0, initialNotificationLimit).forEach(notification =&gt;
                      ul.insertAdjacentHTML("beforeend", (createNotificationListItem(notification))));
              }
  
          } else {
              ul.insertAdjacentHTML("beforeend", "&lt;span class='text-muted'&gt;You don't have any unread notifications!&lt;/span&gt;");
          }
      });
  }
  
  function createNotificationListItem(notification) {
      var { NotificationId, NotificationBody, NotificationTitle, DateTime } = notification.Notification;
  
      return `&lt;li class="media"&gt;
                  &lt;div class="mr-3 position-relative"&gt;
                      &lt;img src="" width="36" height="36" class="rounded-circle" alt=""&gt;
                  &lt;/div&gt;
                  &lt;div class="media-body"&gt;
                      &lt;div class="media-title"&gt;
  
                         //In this route, which goes to my Announcement Action in my .NET Core,
                         // which will set isRead property to "True"
                          &lt;a href="/announcement/${NotificationId}"&gt;
                              &lt;span class="font-weight-semibold"&gt;${NotificationTitle}&lt;/span&gt;
                              &lt;span class="text-muted float-right font-size-sm"&gt;${DateTime}&lt;/span&gt;
                          &lt;/a&gt;
                      &lt;/div&gt;
                      &lt;span class="text-muted"&gt;${NotificationBody.substring(0, 25)}...&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/li&gt;`
  }
  </code></pre>
  
  <p>Ok, so this is my projects notifications part.</p>
  
  <p>**ERROR / PROBLEMS **</p>
  
  <p>When I <strong>published</strong> my site with FTP, a Console error appeared.</p>
  
  <p>But the main problem is, till my friend told me that there is an error with notifications, and a console error, I didnt actually know that there was an error. Because on my computer everything was working,
  and I tried on another friends computer, and also working, but the others told me that on their computer, they got this error.</p>
  
  <p>Error was, </p>
  
  <pre><code>Cannot read property undefined  'unreadNotifications'  =&gt; notification.js
  </code></pre>
  
  <p>I tried to told them to remove browser <strong>cache</strong> history, for some of them it worked, and for some of them it didn't.. </p>
  
  <p>I really got stuck in here, I don't know how to google it...</p>
  
  <p><strong>NOTE:</strong> For your information, my endpoint has the data, and my actions or my ef methods are all working fine...</p>
  
  <p>How can a code works differently in other computers, and also I didn't know how to <strong>Google</strong> this problem, and as you can understand I'm not an expert...</p>
  
  <p><strong>NOTE:</strong> Last thing my Cors setup is:</p>
  
  <pre><code>services.AddCors(o =&gt; o.AddPolicy("MyPolicy", builder =&gt;
  {
         builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
  }));
  </code></pre>
  
  <p><strong>EDIT</strong> : I've tried to log in as the same user on different computers, as I've mentioned above,
  when I type "http://{my-site}/api/notifications", on my computer and some others , I got the JSON object (3 notifications so far.), but on the other computers this <strong>endpoint</strong> return an <strong>empty array => []</strong></p>
  
  <p><strong>Second EDIT :</strong> When I debugged my js file on browser, this is my response, it cant access the <strong>cookies</strong> which are set to <strong>HttpOnly</strong>, I tried to fetch with <code>credentials:same-origin</code>, didn't actually worked.</p>
  
  <p><code>response = Response {type: "cors", url: "{mysite}.com/account/login?ReturnUrl=%2Fapi%2Fnotifications", redirected: true, status: 200, ok: true, …}</code></p>