title: Run Website from asp.net core console app
body: <p>I have a console application that will be a service, it has a website to configure the service. </p>
  
  <p>I have built my website and when i run that project it works fine.</p>
  
  <p>I referenced my web project in the console application and inside there i use the following code to start the website.</p>
  
  <pre><code>    Task.Factory.StartNew(new Action(() =&gt; Website.Program.Main(null)), TaskCreationOptions.LongRunning);
  </code></pre>
  
  <p>my code in the website program class is </p>
  
  <pre><code>    public class Program
  {
      public static void Main(string[] args)
      {
          CreateWebHostBuilder(args).Build().Run();
      }
  
      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
          WebHost.CreateDefaultBuilder(args)
              .UseStartup&lt;Startup&gt;()
              .UseUrls("http://0.0.0.0:1234");              
  }
  </code></pre>
  
  <p>The issue i have is the website now cannot find the css files and javascript files in wwwRoot, i tried publishing the application to the debug folder of the console application but this did not work. if i don't publish there is only dll files in the debug folder of the console application if i do publish all the files are there but the views cannot find them.</p>
  
  <p>I am using ~ in the the views to find files.</p>
  
  <p>Ideally I want a service that can be installed host its own website and API without it showing in the local computers IIS or need to enable IIS through windows features.</p>
  
  <p>edit Startup.cs</p>
  
  <pre><code>  public class Startup
  {
      public Startup(IConfiguration configuration)
      {
          Configuration = configuration;
      }
  
      public IConfiguration Configuration { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              // This lambda determines whether user consent for non-essential cookies is needed for a given request.
              options.CheckConsentNeeded = context =&gt; true;
              options.MinimumSameSitePolicy = SameSiteMode.None;
          });
          services.AddAuthentication(opt =&gt;
          {
              opt.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              opt.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
              opt.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
          }).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =&gt;
          {
              options.Cookie.Name = "TmiginScheme";
              options.LoginPath = "/Account/Login";
              options.LogoutPath = "/Account/Logout";
              options.AccessDeniedPath = "/Home/AccessDenied";
              options.ExpireTimeSpan = TimeSpan.FromDays(14);
              options.SlidingExpiration = true;
          });
          services.AddDistributedMemoryCache();
          services.AddSession();
  
          services.Configure&lt;SettingsViewModel&gt;(Configuration.GetSection("Settings"));
          services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          app.UseSession();
          app.UseAuthentication();
  
          var cookiePolicyOptions = new CookiePolicyOptions
          {
              MinimumSameSitePolicy = SameSiteMode.Strict,
          };
  
          app.UseCookiePolicy(cookiePolicyOptions);
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler("/Home/Error");
          }
          app.UseStaticFiles();
  
      app.UseCookiePolicy();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
      }
  }
  </code></pre>