Questions tagged [asp.net-core-1.0]
Use this tag for questions specifically related to ASP.NET Core 1.0, in addition to using the 'ASP.NET Core' tag. ASP.NET Core 1.0 was the first release of ASP.NET Core and was originally intended to be ASP.NET 5.
asp.net-core-1.0
878
questions
300
votes
24
answers
449k
views
How to get the current logged in user ID in ASP.NET Core?
I've done this before with MVC5 using User.Identity.GetUserId() but that doesn't seem to work here.
The User.Identity doesn't have the GetUserId() method.
I am using Microsoft.AspNet.Identity.
180
votes
16
answers
412k
views
How to read connection string in .NET Core?
I want to read just a connection string from a configuration file and for this add a file with the name "appsettings.json" to my project and add this content on it:
{
"ConnectionStrings": {
"...
157
votes
13
answers
216k
views
How to get current url in view in asp.net core 1.0
In previous versions of asp.net, we could use
@Request.Url.AbsoluteUri
But it seems it's changed. How can we do that in asp.net core 1.0?
141
votes
13
answers
81k
views
JSON properties now lower case on swap from ASP .Net Core 1.0.0-rc2-final to 1.0.0
I've just swapped our project from ASP .Net Core 1.0.0-rc2-final to 1.0.0. Our website and client have stopped working because of the capitalization of JSON properties. For example, this line of ...
102
votes
10
answers
135k
views
Read appsettings.json in Main Program.cs
First of all my main purpose is to setup the IP and Port for my application dynamically.
I'm using IConfiguration to inject a json config file, like some tutorial mentioned.
However, I can't ...
101
votes
18
answers
89k
views
How to publish environment specific appsettings in .Net core app?
I have 3 environment specific appsettings files in my .Net core application
in project.json I have setup publishOptions like this. ( based on suggestion here)
"publishOptions": {
"include": [
...
97
votes
15
answers
75k
views
.NET Core: Remove null fields from API JSON response
On a global level in .NET Core 1.0 (all API responses), how can I configure Startup.cs so that null fields are removed/ignored in JSON responses?
Using Newtonsoft.Json, you can apply the following ...
92
votes
3
answers
99k
views
How to save IFormFile to disk?
I'm trying to save a file on disk using this piece of code.
IHostingEnvironment _hostingEnvironment;
public ProfileController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = ...
85
votes
6
answers
64k
views
How to set aspnetcore_environment in publish file?
I have ASP.NET Core application (Web Api). The documentation has explained working with multiple environments, however it failed to explain how to set aspnetcore_environment when publishing the web ...
83
votes
13
answers
55k
views
No executable found matching command "dotnet-ef"
I'm doing a project sample by using ASP.Net Core RC2 with Microsoft.EntityFramework.Core and SQLite.
I've followed this tutorial:
https://damienbod.com/2015/08/30/asp-net-5-with-sqlite-and-entity-...
82
votes
13
answers
59k
views
How to get "Manage User Secrets" in a .NET Core console-application?
When I create a new ASP .NET Core Web-Application, I can right-click the project in Visual Studio, and I see a context-menu entry called "Manage User Secrets".
When I create a new .NET Core Console-...
79
votes
1
answer
28k
views
Replacement of AssemblyBuilder.DefineDynamicAssembly in .NET Core
How do I port the following code to .NET Core?
AppDomain.CurrentDomain.DefineDynamicAssembly(
new AssemblyName(
Guid.NewGuid().ToString()),
...
76
votes
14
answers
84k
views
No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered
I'm having this problem: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. In asp.net core 1.0, it seems that when the action try to render ...
76
votes
3
answers
65k
views
Equivalent for .HasOptional in Entity Framework Core 1 (EF7)
Consider two classes.
public class File
{
[Key]
public string Id { get; set; }
public string Message_Id { get; set; }
internal Message Message { get; set; }
}
public class Message
...
69
votes
3
answers
51k
views
'IConfiguration' does not contain a definition for 'Get'
Originally, I had the code in 1.0.0-rc1-beta6.
public static IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// ...
66
votes
6
answers
35k
views
Injection of IUrlHelper in ASP.NET Core
In RC1, IUrlHelper could be injected in services (with services.AddMvc() in startup class)
This doesn't work anymore in RC2. Does anybody know how to do it in RC2 as just newing up a UrlHelper ...
66
votes
5
answers
52k
views
How to set .NET Core in #if statement for compilation
I created a multi-targeted framework project. I use something like this:
#if NET40
Console.WriteLine("Hello from .NET Core 4");
#endif
But I can't find a wildcard for .NET Core. I tried:
...
61
votes
5
answers
62k
views
Basic Authentication in ASP.NET Core
Question
How can I implement Basic Authentication with Custom Membership in an ASP.NET Core web application?
Notes
In MVC 5 I was using the instructions in this article which requires adding a module ...
58
votes
4
answers
108k
views
How to add IHttpContextAccessor in the Startup class in the DI in ASP.NET Core 1.0?
In ASP.NET Core RC 1 I used the following code to retrieve the value of context (full address of the page). Then I recorded this value in the configuration.
public class Startup
{
public ...
56
votes
10
answers
59k
views
How to specify the view location in asp.net core mvc when using custom locations?
Let's say I have a controller that uses attribute based routing to handle a requested url of /admin/product like so:
[Route("admin/[controller]")]
public class ProductController: Controller {...
56
votes
6
answers
103k
views
How to stream with ASP.NET Core
How to properly stream response in ASP.NET Core?
There is a controller like this (UPDATED CODE):
[HttpGet("test")]
public async Task GetTest()
{
HttpContext.Response.ContentType = "text/plain";
...
55
votes
7
answers
42k
views
Form submit resulting in "InvalidDataException: Form value count limit 1024 exceeded."
I have created an mvc site and I'm posting a large amount of json form data (Content-Type:application/x-www-form-urlencoded)
back to the mvc controller. When I do this, I receive a 500 response that ...
52
votes
4
answers
44k
views
ASP.NET Core Configuration Section in Startup
I am migrating a ASP.NET 5 RC1 project to ASP.NET Core, and have come across an interesting issue I've not yet seen, or found a solution for.
In order to use configuration settings within Startup I ...
51
votes
26
answers
197k
views
Value cannot be null. Parameter name: connectionString appsettings.json in starter
I am trying to write my connection string in my appsettings.json file and bring it into my startup file but I keep getting a Value cannot be null.
Parameter name: connectionString. I have been using ...
51
votes
3
answers
119k
views
Access Web.config settings in Asp.Net Core App?
I understand that asp.net core has a new configuration system that is quite flexible and that's great. But there are things I like about the web.config based configuration system from .net 4.x. For ...
49
votes
3
answers
25k
views
asp.net core 1.0 web api use camelcase
On RC2 the same code returns json format with camel case. After netcore 1.0 release i started new project and the same code is returning json in lowercase.
Tried multiple solutions but none of them ...
49
votes
6
answers
82k
views
Read solution data files ASP.Net Core
I have an ASP.NET Core (1.0-rc1-final) MVC solution and I wish to store a simple text file within the project which contain a list of strings which I read into a string array in my controller.
Where ...
49
votes
2
answers
24k
views
Alternative to System.Web.Security.Membership.GeneratePassword in aspnetcore (netcoreapp1.0)
Is there any alternative to System.Web.Security.Membership.GeneratePassword in AspNetCore (netcoreapp1.0).
The easiest way would be to just use a Guid.NewGuid().ToString("n") which is long enough to ...
47
votes
7
answers
74k
views
Error handling (Sending ex.Message to the client)
I have an ASP.NET Core 1.0 Web API application and trying to figure out how to pass the exception message to the client if a function that my controller is calling errors out.
I have tried so many ...
45
votes
2
answers
37k
views
ASPNET Core Server Sent Events / Response flush
While there is no official documentation, does anyone know how SSE may be implemented using ASP.NET Core?
I suspect one implementation may use custom middleware, but maybe it is possible to do that ...
44
votes
13
answers
134k
views
ASP.NET Core 404 Error on IIS 10
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 ...
43
votes
2
answers
30k
views
ASP.NET Core MVC controllers in separate assembly
I'm using ASP.NET MVC Core RC-2. I have a web project targeting the full .NET framework. I also have a separate class library in the solution, also targeting the full framework.
In the class library, ...
43
votes
12
answers
49k
views
HttpContext.Authentication.SignOutAsync does not delete auth cookie
According to ASP.NET Core documentation the method HttpContext.Authentication.SignOutAsync() must delete the authentication cookie as well.
Signing out
To sign out the current user, and delete their ...
41
votes
10
answers
12k
views
AWS Elastic Beanstalk environment variables in ASP.NET Core 1.0
How do I get environment variables from elastic beanstalk into an asp.net core mvc application? I have added a .ebextensions folder with app.config file in it with the following:
option_settings:
- ...
40
votes
1
answer
26k
views
ASP.NET Core - Create custom model validation
In previous versions of ASP.NET MVC the way to add custom validation to your model was by implementing the IValidatableObject and implementing your own Validate() method.
Here's what I have ...
36
votes
10
answers
84k
views
Change default format for DateTime parsing in ASP.NET Core
I get a Date in an ASP.NET Core Controller like this:
public class MyController:Controller{
public IActionResult Test(DateTime date) {
}
}
The framework is able to parse the date, but only ...
36
votes
3
answers
30k
views
Is .NET Core Runtime backwards compatible with previous releases?
If I've installed the latest version of the .NET Core Runtime (as of now, that's version 2.2.3):
https://dotnet.microsoft.com/download/dotnet-core/2.2
Is that one installation backwards-compatible ...
35
votes
6
answers
36k
views
EntityFramework code first: Set order of fields
I am using EntityFramework with the "Code first" approach with migrations.
I have successfully generated tables from my models, but the columns are being added in an alphabetical order rather than ...
34
votes
3
answers
26k
views
Run NUnit tests in .NET Core
I am trying to run unit tests for my C# project with .NET Core.
I am using a Docker container for the runtime.
Dockerfile
FROM microsoft/dotnet:0.0.1-alpha
RUN mkdir /src
WORKDIR /src
ADD . /src
RUN ...
32
votes
1
answer
56k
views
Unable to find image 'xxxx' locally
Basically I created an asp.net mvc project. I added a Dockerfile in the project folder.
FROM microsoft/aspnet:1.0.0-rc1-update1
ADD . /app
WORKDIR /app/approot
EXPOSE 5004
ENTRYPOINT ["./web"]
Now ...
31
votes
2
answers
12k
views
EF Core Add function returns negative id
I noticed a weird thing today when I tried to save an entity and return its id in EF Core
Before:
After:
I was thinking about if it was before calling saveChanges() but it works with another ...
30
votes
2
answers
15k
views
How to disable TypeScript compilation in .Net Core projects?
I have a Visual Studio 2015 ASP.Net Core project that contains a folder of typescript files.
My question is how can I prevent VS from trying to compile the TypeScript files? I don't want them ...
29
votes
4
answers
19k
views
Authenticate against Active Directory in .NET Core 1.0 application?
With the recent release of .NET Core 1.0, we're in the process of migrating our RC1 applications to the final release. The only piece we can't seem to figure out is how to integrate Active Directory ...
27
votes
2
answers
27k
views
Override global authorize filter in ASP.NET Core 1.0 MVC
I am trying to set up authorization in ASP.NET Core 1.0 (MVC 6) web app.
More restrictive approach - by default I want to restrict all controllers and action methods to users with Admin role. So, I ...
27
votes
3
answers
16k
views
ResponseCache attribute does not cache data on client side
In ASP.NET Core application I have a action method that returns some data. I wanted to cache this data on client side. So based on the documentation here i can use ResponseCache attribute on the ...
26
votes
1
answer
20k
views
Library NuGet configuration is invalid
VS2015 Update 3.
I created a plain .net core class library.
Right-click on Project->References-> Manage Nuget packages
throws the following error?
What is missing?
25
votes
5
answers
24k
views
How to get bin folder in ASP.NET Core 1.0
With asp.net core 1.0 There are lots of functionality added. But there is not way to get Bin Folder path.
Can anyone please know how we can get the bin folder path for asp.net core 1.0 application.
24
votes
1
answer
20k
views
How to register an instance to the ServiceCollection in ASP.NET Core 1.0 RC2
I'm migrating my web app from ASP.NET Core RC1 to RC2. In RC2 the IServiceCollection doesn't have the AddInstance method anymore. How do I get the Configuration registered?
Here how it was done in ...
23
votes
2
answers
16k
views
Input placeholder from ViewModel metadata in ASP.NET Core 1.0
Is it possible to set up the built-in asp-for tag helper to take the input placeholder from the [Display(Prompt = "This is the placeholder")] attribute in the view model.
[Display(Name="Name", Prompt ...
23
votes
7
answers
30k
views
AntiXSS in ASP.Net Core
Microsoft Web Protection Library (AntiXSS) has reached End of Life. The page states "In .NET 4.0 a version of AntiXSS was included in the framework and could be enabled via configuration. In ASP.NET ...