Reputation: 115
I am starting a new web application, but this time I am using .net core mvc. I have been struggling with all the changes from mvc 5. That said, I was making some great strides when the application stopped running. It compiles error free but when it runs the console does not come up anymore (as it did before) and when the browser opens it just says the site cannot be reached
I don't know what specific code to post as I have no clue where the issue is. It all started when I tried to force HTTPS in the Startup.cs but I have since commented that out and yet it still does not work. Here is Startup.cs in case that helps. How can I get the console back up?
using Bidz4hire;
using Bidz4Hire.Data;
using Bidz4Hire.Models;
using Bidz4Hire.Options;
using Bidz4Hire.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using System;
using System.IO;
namespace Bidz4Hire
{
public class Startup
{
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
{
Configuration = configuration;
// Get the root path on the server [AGD]
GF.RootPath = hostingEnvironment.WebRootPath;
}
public IConfiguration Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
//services.Configure<MvcOptions>(options =>
//{
// options.Filters.Add(new RequireHttpsAttribute());
//});
services.AddDbContext<Bidz4HireV1>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Bidz4HireV1")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<Bidz4HireV1>()
.AddDefaultTokenProviders();
services.Configure<IdentityOptions>(options =>
{
// Password settings
options.Password.RequireDigit = true;
options.Password.RequiredLength = 8;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = true;
options.Password.RequireLowercase = true;
options.Password.RequiredUniqueChars = 6;
// Lockout settings
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.AllowedForNewUsers = true;
// User settings
options.User.RequireUniqueEmail = true;
});
services.ConfigureApplicationCookie(options =>
{
// Cookie settings
options.Cookie.HttpOnly = true;
options.Cookie.Expiration = TimeSpan.FromDays(150);
options.LoginPath = "/Account/Login"; // If the LoginPath is not set here, ASP.NET Core will default to /Account/Login
options.LogoutPath = "/Account/Logout"; // If the LogoutPath is not set here, ASP.NET Core will default to /Account/Logout
options.AccessDeniedPath = "/Account/AccessDenied"; // If the AccessDeniedPath is not set here, ASP.NET Core will default to /Account/AccessDenied
options.SlidingExpiration = true;
});
services.AddOptions();
// Add application services.
services.AddTransient<IEmailSender, EmailSender>();
BidzGlobalConfig.appSettings = new BidzSettings();
Configuration.Bind("BidzSettings", BidzGlobalConfig.appSettings);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
//var options = new RewriteOptions()
// .AddRedirectToHttps();
//app.UseRewriter(options);
//app.UseStaticFiles(); //be able to serve files in wwwroot
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"Downloads")),
RequestPath = new PathString("/Downloads")
});
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Upvotes: 4
Views: 1058
Reputation: 25
Open launchSettings.json
under Properties folder.
here you will find settings for IIS Express, http, https_ etc. Like below
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:39766",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5042",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Create one with your application name or your desired name and put it under the "profiles"
"Bidz4Hire": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:[your_localhost_port]",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Make sure commandName is set to Project
Now instead of IIS Express choose your project name Bidz4Hire, and run it.
Upvotes: 0
Reputation: 115
It would appear that the issue stemmed from the run menu drop-down being set to "IIS Express" instead of my application name. When I set it back to the application name the console pops back up and it runs the application. Core is so different from MVC5 it is really throwing me for a loop.
Upvotes: 3