Unable to get Session working ASP - asp.net

Using VS 2015 with beta 7 of MVC 6 I am having issues getting Session configured for use in my web application.
When I create a new ASP.NET Web Application project I choose the Web Application ASP.NET 5 Preview Template.
I then edited the Startup.cs by adding the following line:
services.AddCaching();
I then added the following line:
services.AddSession();
At that point the editor prompted me to add a reference to this depencency:
"Microsoft.AspNet.Session": "1.0.0-beta8"
After doing so I get the following errors:
Error CS7069 Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found WebApplication1.DNX 4.5.1 c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs 29
Error CS7069 Reference to type 'IConfigurationProvider' claims it is defined in 'Microsoft.Framework.Configuration.Abstractions', but it could not be found WebApplication1.DNX Core 5.0 c:\users\texasmike\documents\visual studio 2015\Projects\SessionTesting\src\WebApplication1\Startup.cs 29
I have attempted a thorough search but haven't found any answers.
Here is the complete Startup.cs:
using Microsoft.AspNet.Authentication.Facebook;
using Microsoft.AspNet.Authentication.MicrosoftAccount;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics.Entity;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Data.Entity;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
using WebApplication1.Models;
using WebApplication1.Services;
namespace WebApplication1
{
public class Startup
{
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Setup configuration sources.
var builder = new ConfigurationBuilder(appEnv.ApplicationBasePath)
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// This reads the configuration keys from the secret store.
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Entity Framework services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Configure the options for the authentication middleware.
// You can add options for Google, Twitter and other middleware as shown below.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
services.Configure<FacebookAuthenticationOptions>(options =>
{
options.AppId = Configuration["Authentication:Facebook:AppId"];
options.AppSecret = Configuration["Authentication:Facebook:AppSecret"];
});
services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
{
options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
});
// Add MVC services to the services container.
services.AddMvc();
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers.
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json.
// services.AddWebApiConventions();
// Register application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
// Caching
services.AddCaching();
// Session
services.AddSession();
}
// Configure is called after ConfigureServices is called.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
loggerFactory.AddDebug();
// Configure the HTTP request pipeline.
// Add the following to the request pipeline only in development environment.
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage();
app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
}
else
{
// Add Error handling middleware which catches all application specific errors and
// sends the request to the following path or controller action.
app.UseErrorHandler("/Home/Error");
}
// Add static files to the request pipeline.
app.UseStaticFiles();
// Add cookie-based authentication to the request pipeline.
app.UseIdentity();
// Add authentication middleware to the request pipeline. You can configure options such as Id and Secret in the ConfigureServices method.
// For more information see http://go.microsoft.com/fwlink/?LinkID=532715
// app.UseFacebookAuthentication();
// app.UseGoogleAuthentication();
// app.UseMicrosoftAccountAuthentication();
// app.UseTwitterAuthentication();
// Add MVC to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
// Uncomment the following line to add a route for porting Web API 2 controllers.
// routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
});
}
}
}
Here is the complete project.json:
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-WebApplication1-36d27e1d-a781-4628-91dc-8a80cb46fd14",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta7",
"EntityFramework.SqlServer": "7.0.0-beta7",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta7",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
"Microsoft.AspNet.Session": "1.0.0-beta8",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta7",
"Microsoft.Framework.Logging": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.Framework.Logging.Debug": "1.0.0-beta7",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}

Related

Publish ASP.NET Core to Azure fails unexpectedly

I have a project based on ASP.NET Core 1.0. I can build and run locally without any problems, but if I try to publish the project to Azure using the publish mechanism in Visual Studio 2015 (even if I try to publish locally to a folder in file system or using FTP) it fails unexpectedly without giving me any concrete message. If I run preview I always get this log:
The "Publish" task failed unexpectedly.
System.Exception:
Publishing Project.Web for .NETFramework,Version=v4.5.2/win7-x64
at Microsoft.DotNet.Tasks.Publish.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
If I try to publish ignoring this error or if I do not try to get the preview I get this:
1>------ Publish started: Project: Kunato.Web, Configuration: Debug Any CPU ------
rmdir /S /Q "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54\"
Environment variables:
DOTNET_CONFIGURE_AZURE=1
Path=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "C:\Code\Git\Web_KuNaTo\src\Kunato.Web" --framework net452 --output "C:\Users\thimo\AppData\Local\Temp\PublishTemp\Kunato.Web54" --configuration Debug --no-build
Publishing Kunato.Web for .NETFramework,Version=v4.5.2/win7-x64
1>Publish failed due to build errors. Check the error list for more details.
========== Build: 0 succeeded, 0 failed, 7 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
If I the do as requested and look at the error list, there is no error and everything looks good. Are there any other log files or anything to check where the problem might be?
project.json
{
"userSecretsId": "aspnet-Kunato.Web-753ff034-0ada-4809-84a8-a4f157c4ea43",
"dependencies": {
"Kunato.Common": "1.0.0-*",
"Kunato.Core": "1.0.0-*",
"Kunato.DataAccess": "1.0.0-*",
"Kunato.Edi": "1.0.0-*",
"Kunato.Entities": "1.0.0-*",
"Kunato.Localization": "1.0.0-*",
"ediFabric.Framework": "6.7.0",
"LumenWorksCsvReader": "3.9.0",
"Sendgrid": "6.3.4",
"StackExchange.Redis": "1.1.0-alpha2",
"StackExchange.Redis.StrongName": "1.1.0-alpha2",
"Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
"Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
"Microsoft.AspNetCore.Authentication.Facebook": "1.0.0",
"Microsoft.AspNetCore.Authentication.Google": "1.0.0",
"Microsoft.AspNetCore.Authentication.MicrosoftAccount": "1.0.0",
"Microsoft.AspNetCore.Authentication.Twitter": "1.0.0",
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.Cors": "1.0.0",
"Microsoft.AspNetCore.Session": "1.0.0",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0",
"Microsoft.Extensions.Caching.Redis": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
"version": "1.0.0-preview2-final",
"type": "build"
}
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
"version": "1.0.0-preview2-final",
"imports": [
"portable-net45+win8"
]
}
},
"frameworks": {
"net452": {}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "npm install", "bower install" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Kunato.Web.Services;
using Kunato.DataAccess;
using Kunato.Entities.Core;
using Kunato.Web.Helpers;
using System.Globalization;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Options;
using Kunato.DataAccess.Data;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace Kunato.Web
{
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add Application Insights data collection services to the services container.
services.AddApplicationInsightsTelemetry(Configuration);
// Add framework services.
services.AddDbContext<KunatoDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Kunato.Web")));
services.AddIdentity<KunatoUser, KunatoRole>(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 4;
options.Password.RequireLowercase = false;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#-.";
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<KunatoDatabaseContext>()
.AddDefaultTokenProviders();
// Add session
services.AddSession(options =>
{
options.CookieName = ".kunato.Session";
options.IdleTimeout = TimeSpan.FromMinutes(30);
});
// Add localization
services.AddLocalization();
// Register Version service
services.AddSingleton<IDeploymentEnvironment, DeploymentEnvironment>();
// Add localization to the request pipeline
var dtf = new DateTimeFormatInfo
{
ShortDatePattern = "dd.MM.yyyy",
LongDatePattern = "dd.MM.yyyy HH:mm",
ShortTimePattern = "HH:mm",
LongTimePattern = "HH:mm"
};
var nf = new NumberFormatInfo
{
CurrencyDecimalSeparator = ",",
CurrencyGroupSeparator = ".",
NumberDecimalSeparator = ",",
NumberGroupSeparator = ".",
NumberDecimalDigits = 3
};
// Add MVC services to the services container.
services.AddMvc().AddJsonOptions(options =>
{
// handle loops correctly
options.SerializerSettings.ReferenceLoopHandling =
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
// use standard name conversion of properties
options.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
// include $id property in the output
options.SerializerSettings.PreserveReferencesHandling =
PreserveReferencesHandling.Objects;
})
.AddViewLocalization()
.AddDataAnnotationsLocalization();
// Register Filters
services.AddScoped<LanguageActionFilter>();
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
//new CultureInfo("en-US") { DateTimeFormat = dtf },
//new CultureInfo("en") { DateTimeFormat = dtf },
new CultureInfo("de-DE") { DateTimeFormat = dtf, NumberFormat = nf },
new CultureInfo("de") { DateTimeFormat = dtf, NumberFormat = nf }
//new CultureInfo("en-US"),
//new CultureInfo("en"),
//new CultureInfo("de-DE"),
//new CultureInfo("de")
};
options.DefaultRequestCulture = new RequestCulture(culture: "de-DE", uiCulture: "de-DE");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
// Add application settings from config
services.Configure<ApplicationSettings>(Configuration.GetSection("ApplicationSettings"));
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
// Register KunatoBaseData
//services.AddTransient<KunatoBaseData>();
//services.AddTransient<KunatoSampleData>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
// Add Application Insights to the request pipeline to track HTTP request telemetry data.
app.UseApplicationInsightsRequestTelemetry();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
try
{
using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
serviceScope.ServiceProvider.GetService<KunatoDatabaseContext>().Database.Migrate();
// Seeding the basic data to the database
var kunatoBaseData = app.ApplicationServices.GetService<KunatoBaseData>();
await kunatoBaseData.InitializeDataAsync();
// Seeding sample data to the database
//var kunatoSampleData = app.ApplicationServices.GetService<KunatoSampleData>();
//await kunatoSampleData.InitializeDataAsync();
}
}
catch { }
app.UseStaticFiles();
app.UseIdentity();
// Add session
app.UseSession();
// Add localization
var locOptions = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(locOptions.Value);
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

ASP.NET Core 1 and Entity Framework (Npgsql) breaks Startup class and says: app.UseMvc method not available

I want to use the Entity Framework 7 in my ASP.NET Core 1 application to connect to a PostgreSQL database.
If I add EntityFramework.Commands (7.0.0-beta5) and EntityFramework7.Npgsql (3.1.0-rc1-3) to my project.json file:
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-beta5",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta5",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta5",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta5",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta5",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta5",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta5",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta5",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta5",
"Microsoft.Framework.Logging": "1.0.0-beta5",
"Microsoft.Framework.Logging.Console": "1.0.0-beta5",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta5",
"EntityFramework.Commands": "7.0.0-beta5",
"EntityFramework7.Npgsql": "3.1.0-rc1-3"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
I get errors in my Startup.cs
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet.Hosting;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Logging;
namespace Suplim.Web.Platform
{
public class Startup
{
public IConfiguration Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.MinimumLevel = LogLevel.Information;
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
else
{
app.UseErrorHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Then Visual Studio says that in my Startup.Configure() method it can not find the methods:
app.UseBrowserLink
app.UseErrorPage
app.UseErrorHandler
app.UseStaticFiles
app.UseMvc
It says
Core DNX 4.5.1 not available
Core DNX Core 5 available
But both packages are loaded and available in the Visual Studio references structure (DNX 4.5.1 and DNX Core 5).
If I remove the EntityFramework.Commands and EntityFramework7.Npgsql packages everything works fine.
Why does the Entity Framework affect my Startup class? Are the versions incompatible (beta5 and rc1-final)? If yes what can I do?
I do not understand the problem.
You are using an rc1 package for EF and beta5 for anything else. You can't mix package versions. Move everything to rc1 (beta5 is a thing of the past) and use the rc1 runtime (dnx) otherwise things will break.
I have already tried to set the same version to all packages but some packages are still beta-* and others are rc1-final. These are the newest packages (I removed the EntityFramework7.Npgsql and other not needed packages for testing):
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Framework.Logging": "1.0.0-beta8",
"Microsoft.Framework.Logging.Console": "1.0.0-beta8",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final"
},
And my global.json is now:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-rc1-final",
"runtime": "clr",
"architecture": "x86"
}
}
Now it can not find the EntityFramework.Commands and Microsoft.AspNet.Mvc packages (both with different version number than 1.0.0) in the DNX 4.5.1 reference. In the DNX Core 5 reference it finds nothing, all packages are unresolved.
It is like the old DLL hell ...
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7"
needs to be changed to
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final"
As the other responder says you are mixing and matching. You should have everything on the same version or don't use it.

ASP.NET 5 host application in IIS 8 with https bindings

Earlier I was having issue hosting ASP.NET 5 application in IIS and now I am able to host it via http. Here is my old post that contains details.
For past couple days I have been trying to enable https for my application over port 443. In launchSetting.json file I updated iisexpress settings to "applicationUrl": "https://servername:443/" with valid certificate. but I still get 404 error when I browse the application in the browser.
Here is my launchSettings.json file:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://servername:443/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"Hosting:Environment": "Development"
}
},
"web": {
"commandName": "web",
"environmentVariables": {
"Hosting:Environment": "Development"
}
}
}
}
Here is my project.json file:
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.Net.Http.Server": "1.0.0-beta5",
"dnx-clr-win-x64": "1.0.0-rc1-update1",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
}
Startup.cs file:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc() // Add MVC Dependency.
.AddJsonOptions(
opt =>
{
opt.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // Api convert all property names to CamelCase.
}
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory LoggerFactory)
{
LoggerFactory.AddDebug(LogLevel.Warning);
app.UseIISPlatformHandler();
app.UseStaticFiles();
app.UseMvc(config =>
{
config.MapRoute(
name: "Default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "App", Action = "Index" }
);
}); // Use MVC from Dependency.
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
I am not sure if it is right way to enable https in the application, but IIS bindings are configured correctly with valid certificate. So I am not sure why it is still throwing 404 error.
Any help from community is really appreciated. :)

Add dll to MVC6 or use old web service

I need to reference a dll which calls an old web service (not svc, but the older one). I'm not quite sure how to go about doing that. I'm using the RC1 version. I could call the web service directly but I'm not sure how to do that either in MVC6.
If I add the dll directly I get the error:
The name '*' does not exist in the current context
FieldOps.DNX Core 5.0
Here's what part of my project.json looks like where the library added is called "MyLibrary":
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Runtime.Serialization": "4.0.0.0",
"System.ServiceModel": "4.0.0.0"
},
"dependencies": { "MyLibrary": "2.2.0" }
},
"dnxcore50": {
"dependencies": {
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Primitives": "4.1.0-beta-23516",
"System.ServiceModel.Http": "4.0.11-beta-23516",
"System.ServiceModel.NetTcp": "4.1.0-beta-23516",
"System.ServiceModel.Duplex": "4.0.1-beta-23516",
"System.ServiceModel.Security": "4.0.1-beta-23516",
"System.Net.NameResolution": "4.0.0-beta-23516",
"System.Net.Security": "4.0.0-beta-23516",
"System.Security.Principal.Windows": "4.0.0-beta-23516",
"System.Diagnostics.Tools": "4.0.1-beta-23516"
}
}
},

SQLite reference in ASP.NET 5 WebApp

App version - ASP.NET 5 beta7 build. Entity 7. OS Win x64.
I have a problem with attaching Sqlite to my app. I'm recieving Unable to load DLL 'sqlite3' (System.DllNotFoundException) or IncorrectFormat (System.BadImageFormatException) Errors.
It seems that app can't find SQLite dll & lacks proper reference.
When switching between dnx versions, errors change (tried in both clr & coreclr). Errors - Former for x86, latter for x64. However, in both instances dnx & sqlite versions are matched.
My global.
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-beta7",
"runtime": "clr",
"architecture": "x64"
}
}
My project.json partial.
"dependencies": {
"Microsoft.AspNet.Diagnostics": "1.0.0-beta7",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta7",
"Microsoft.AspNet.Mvc": "6.0.0-beta7",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta7",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta7",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta7",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta7",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta7",
"Microsoft.Framework.Logging": "1.0.0-beta7",
"Microsoft.Framework.Logging.Console": "1.0.0-beta7",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7",
"Microsoft.AspNet.Session": "1.0.0-beta7",
"EntityFramework.SqlServer": "7.0.0-beta7",
"EntityFramework.Commands": "7.0.0-",
"EntityFramework.Sqlite": "7.0.0-beta7",
"sqlite": "3.8.4.2" (Nuget)
},
There is sqlite3.dll file in root but added reference just transforms into Nuget dependency 3.8.8.x within VS15.
Startup.cs partial.
public void ConfigureServices(IServiceCollection services) {
services.AddEntityFramework()
.AddSqlite()
.AddDbContext<EF7oakContext>(options => options.UseSqlite(Configuration["SqliteString"])); }
... points to config.json.
"Data Source=<path>\\<DBname>.sqlite;"
I tried configuration within Context but if I understand correctly, that's just duplicating config.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
optionsBuilder.UseSqlite("Data Source=<path>\\<dbname>.sqlite;"); }
Simple custom Seed.cs.
public static void Seed(this IApplicationBuilder app) {
var context = app.ApplicationServices.GetService<MyContext>();
if (!context.People.Any()) {
context.People.AddRange(
new Sth { a = "a", b = "b" }
(...)
);
context.SaveChanges(); }
(...)
}
I checked Stack-link-1 and Stack-link-2, but solutions given there are not working.
Recap:
Matched sqlite3 version added as app reference. Used dnvm use [version]
Downloaded latest sqlite (sqlite-link) and put it in my app folder with unchanged name
With each runtime - packages restored with dnu restore
I want to match platform build options for sqlite, but there is no option in VS15, per #B. Clay Shannon similar problem from link no.1 above (earlier ASP v.)
App works with local SQL Server DB.
Migrations working.
I would appreciate any help or even loose suggestions.

Resources