c# - How to force data to update when the site is restarted -


in global.asax.cs, have list of 5 cars (the model, cars.cs, pulls data database):

public class mvcapplication : system.web.httpapplication {     public static list<car> cars = enumerable.range(1,5)         .select(i => new car(i))         .tolist();      protected void application_start()... } 

then use list on front page:

@foreach(var c in mysite.mvcapplication.cars) {     <a href="/car_@c.number">@c.name</a> } 

i can't figure out how force cars variable refresh. quickest way have found log server, open iis, , stop , start website - restarting doesn't work. not sustainable, , i'm sure there's better way...

here's other things i've tried:

  • created script stops website, waits 5 seconds, , starts again. performed stop , start, data did not change.
  • creating sql dependency. not work because use dsn connect database (no way around this).

i need way automate this, user can update info , refresh data without needing me login server every time changes.

break assignment out method , call method once in app start , needed on "refresher" page. set di should need start going down route.

public static list<car> cars;  public static void getcars() {     cars = enumerable.range(1,5)     .select(i => new car(i))     .tolist(); }  protected void application_start() {     getcars(); } 

then call global.getcars() in response ui events on page.


Comments