asp.net-core-1.0

Instantiating IOptions<> in xunit

本秂侑毒 提交于 2019-12-06 02:17:41
问题 I'm trying to write an xunit test for a class (in a .net Core project) that looks something like: public Class FoodStore:IFoodStore { FoodList foodItems; public FoodStore(IOptions<FoodList> foodItems) { this.foodItems = foodItems; } public bool IsFoodItemPresentInList(string foodItemId) { //Logic to search from Food List } }` Note: FoodList is actually a json file, containing data, that is loaded and configured in the Startup class. How can I write an xunit test with appropriate dependency

Does ASP.NET Core web application targeting full dotnet framework work in IIS?

风流意气都作罢 提交于 2019-12-06 02:08:09
问题 I am trying to publish an ASP.NET Core application developed on top of full framework (4.6.1) to IIS. Right now the code is just the base template code created using the Visual Studio "ASP.NET Core (.NET Framework) option. The code compiles fine but when I publish it to Local IIS, it fails to start. I get error like Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Extensions.PlatformAbstractions.PlatformServices' threw an exception. ---> System.IO

Advanced features of Microsoft/Facebook authentifcation not available on Asp .Net Core RC1

醉酒当歌 提交于 2019-12-05 22:47:30
I'm working on a small ASP .NET Core RC1 application and I'm trying to implement the Microsoft/Facebook authentification. The following tutorial is really great and explain all the steps needed: http://www.oauthforaspnet.com/providers/microsoft/ But if I try to use the "advanced" features (like using the Provider property), this one is not available. I've added the following Nuget references in project.json: "Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final", "Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-rc1-final", But I'm not able to use the

How to get Action and Controller name in ASP.Net Core MVC app?

喜欢而已 提交于 2019-12-05 22:43:01
How to get Action and Controller names in ASP.Net MVC Core RC1 Application in Startup.cs ? I want to create a middleware and log the information (I want to Log detailed response to my Database, so I need Action and Controller info.) after following code in configure method of startup.cs - app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=User}/{action=Index}/{id?}"); }); //Want to get Action and controller names here.. You'll want to inject the IActionDescriptorCollectionProvider service into your middleware. From that, you can use the property ActionDescriptors

Specifying the url (port) that a asp.net core 1.0 WebAPI.exe should use in program.cs for both prod and dev

冷暖自知 提交于 2019-12-05 21:21:37
I am doing the following in my asp.net core 1.0 web api (.NET Framework) program.cs to specify which port I want my web api exe to run in for development purposes only: public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .UseUrls(new string[1] { "http://*:12012" }) .Build(); host.Run(); } However, when I publish to production this line causes the WebAPI to error since I want the exe to use the production web-api url i.e. productionWeb/api/values rather than localhost

cannot add reference to .net core Class library asp.net core rc2

天涯浪子 提交于 2019-12-05 20:56:13
问题 I am a newbie in the asp.net net core world and I am struggling to adding a simple ref . I get an error Steps 1) Created an "Asp.net Core Web Application(Net Framework) RC2" 2) Added a Class Library (.Net core) called "ClassLibrary1") 3)Within the web app.Project.json i added a reference to the classlibrary1 like this "dependencies": { "ClassLibrary1": "1.0.0-*", etc... 4) Get error Severity Code Description Project File Line Suppression State Error NU1001 The dependency ClassLibrary1 could

WebTelemetryInitializerBase in ASP.NET Core / MVC6

烈酒焚心 提交于 2019-12-05 11:54:18
Is there an MVC6 compatible version of WebTelemetryInitializerBase that would work with ASP.NET Core (on the full .NET Framework)? See my question here where I asked how to get HttpContext in my temeletry initializers. Unfortunately I didn't specify that I was using MVC 6 and thus no System.Web.HttpContext . Yes, there is a version of this for aspnetcore. Check out the Microsoft Application Insights for ASP.NET Core applications repo. There is an implementation of getting the WebUser found in /src/Microsoft.ApplicationInsights.AspNetCore/TelemetryInitializers/WebUserTelemetryInitializer.cs

ASP.NET Core 404 Error on IIS 10

纵饮孤独 提交于 2019-12-05 10:05:12
问题 I have a problem with ASP.NET Core web application running on IIS 10. I am developing a Single Page Application with AngularJS. The index.html loads perfectly but the backend requests are failing with 404 error code on the IIS 10. From Visual Studio with IIS Express it works perfectly. Can anyone spot how can I fix the backend requests? Here's my Program.cs public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory())

How to get information about runtime .Net Core

陌路散爱 提交于 2019-12-05 08:25:31
I have an app which works on Linux and Windows. I need to know where the app is working for use difference code. Thanks You are probably looking for System.Runtime.InteropServices.RuntimeInformation with the IsOsPlatform function to do runtime checks. Have look at the video tutorial https://channel9.msdn.com/Series/aspnetmonsters/ASPNET-Monsters-Episode-46-Finding-Platform-Information of the ASP.NET Monsters. 来源: https://stackoverflow.com/questions/39207282/how-to-get-information-about-runtime-net-core

.NET Core 1.0, Enumerate All classes that implement base class

假如想象 提交于 2019-12-05 07:53:48
I am working on migrating an ASP.NET project to RC2. I am using AutoFac to try to enumerate classes that implement AutoMapper Profile base class to set up all my mapping profiles without having to call them explicitly. Previously in older version of ASP.NET (even in RC1) I was able to use the following code: public class AutoMapperModule : Module { protected override void Load(ContainerBuilder builder) { builder.RegisterAssemblyTypes().AssignableTo(typeof(Profile)).As<Profile>(); builder.Register(context => { var profiles = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(IoC