Quantcast
Channel: ASP.NET Core
Viewing all 9386 articles
Browse latest View live

ASP.NET and websockets

$
0
0

Since signalr 3 will not be out with the asp.net core rtm release is there any alternative websockets server to use with asp.net core?


Cannot set RC2 to build x86 target

$
0
0

Hi there,

I have an ASP.Cet Core Framework app using RC2.

I need to include a 32 bit foreign com assembly - check: made nuget package, added to local repo and added to project from there.

Now I need to generate x86 web app - with x64 build I see BadImageFormatException for that assembly.

The issue: I can not set build x86 in configuration manager. I can add x86 platform (already exists when add new is checked), but after close and reopen configuration manager the Any Cpu platform is selected and the x64 build is run.

Is there something missing to be installed on Win10x64 for x86 target builds, or general RC2 issue?

Thanks

Bo

JsonOutputFormatter override

$
0
0

Hi,

I wrote a custom JsonOutputFormatter in asp.net core rc2. I am trying to migrate to asp.net core and I can see that I need a constructor(JsonSerializerSettings serializerSettings, ArrayPool<char> charPool) in the class that overrides JsonOutputFormatter.

How can I get these settings?

Thanks 

ViewComponent InvokeAsync function doesn't take 3 arguments

$
0
0

Hi,

I am in Rich Anderson's View Component Tutorial. However, when I ran the code, I got an

/Views/ToDo/Index.cshtml


No overload for method 'InvokeAsync' takes 3 arguments

34.    @await Component.InvokeAsync("PriorityList", 2, false)

Well, I follow it step by step, this is totally against what the tutorial says. It says the InvokeAsync function "can take an arbitrary number of arguments."  What have happened? Here is my ViewComponent class

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using StarterComponentView.Data;
using StarterComponentView.Models;
using Microsoft.AspNetCore.Mvc;

namespace StarterComponentView.ViewComponents
{
    [ViewComponent(Name = "PriorityList")]
    public class PriorityListViewComponent: ViewComponent
    {
        private readonly ApplicationDbContext db;

        public PriorityListViewComponent(ApplicationDbContext context)
        {
            db = context;
        }

        public async Task<IViewComponentResult> InvokeAsync(int maxPriority, bool isDone)
        {
            var items = await GetItemsAsync(maxPriority, isDone);
            return View(items);
        }
        private Task<List<ToDoItem>> GetItemsAsync(int maxPriority, bool isDone)
        {
            return db.ToDo.Where(x => x.IsDone == isDone &&
                                 x.Priority <= maxPriority).ToAsyncEnumerable().ToList(); //.ToListAsync();
        }

    }
}

Here is the calling View

@using StarterComponentView.Models
@model IEnumerable<ToDoItem><h2>ToDo Starter</h2><table class="table"><tr><th>
            @Html.DisplayNameFor(model => model.IsDone)</th><th>
            @Html.DisplayNameFor(model => model.Priority)</th><th>
            @Html.DisplayNameFor(model => model.Name)</th><th></th></tr>
    @foreach (var item in Model)
    {<tr><td>
                @Html.DisplayFor(modelItem => item.IsDone)</td><td>
                @Html.DisplayFor(modelItem => item.Priority)</td><td>
                @Html.DisplayFor(modelItem => item.Name)</td></tr>
    }</table><div>
    @await Component.InvokeAsync("PriorityList", 2, false)</div>

And here is the ViewComponent's view section

@model IEnumerable<StarterComponentView.Models.ToDoItem><h3>Priority Items</h3><ul>
    @foreach (var todo in Model)
    {<li>@todo.Name</li>
    }</ul>

I hate it when myself just copy / paste and the tutorial code doesn't work

Cannot add class library dll in .net framework 4.6.1 or .Net core App 1.0.0

Where did the gulp file go?

$
0
0

Greetings, I was going to ask about if gulp was a replace for BundleConfig and how it works, but now gulp.js is gone too. So what's the replace for it?

hosting.json wwwroot folder location

$
0
0

hi,

In the final release of aspnet core 1, how do we modify the wwwroot folder now? it used to be hosting.json but that no longer exists and i have some gulp plugins which require it, does anyone know where its located?

problems with visual studio 2015 and asp.net core

$
0
0

After upgrading to vs2015 update 3 whenever I am building an asp.net core project and there is an error vs does not show it. Instead if I go to cmd and type dotnet build the error comes up at the same time in VS. Also If I delete bin folder manually from windows explorer and build from vs bin\Debug is produced and it is empty.

Anyone has the same problems?


working with database first in Asp.Net Core

$
0
0

I want to learn Asp.Net Core since it is now RTM. But I am not familiar yet how to work with existing database. In the docs there is an example how to import an database into the project http://bit.ly/2980y46, but it doesn't satisfy my needs and it's just for a specific scenario (the tutorial is for the RC2, not for the RTM, even while the changes are small as much as I see). I want to use also the authentication that Asp.Net gives me, and combine it with the existing database. I want to work with specific tables. In earlier versions of Asp.Net it was very easy to work with existing databases, by just adding an Ado.Net Data Entity and choosing what I need. So, can someone please help me how to work with existing database in Asp.Net Core, and mixing the identity user tables into the database and so on.

adding library references to a ASPNET core .net framework project

$
0
0

Hi,

How do i add a library i want to reference, as when i try at the moment it just says i can't if its not in nuget which is not very useful as this is a private library that i wrote personally

Unable to get session id

$
0
0
How to retrieve session id of current session in asp.net core 1.0?

Unable to pass complex object to web API

$
0
0
How to pass a model object to web api in mvc core from controller?

Core Class Library and Entity Framework Tools

$
0
0

Creating a new Core class library and adding the entity framework tools does not work.  This needs to be fixed for sure.  Using the tools to re-create the database classes in my main project is not good. 

No database provider has been configured for this DbContext

$
0
0

Hi,

I got an error message of

InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

I suspect this is because I tried to add my DbContext into AspnetCore template IdentityDbContext. Here is my DbContext

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }
        public ApplicationDbContext()
        {
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }

        public DbSet<Product> Products { get; set; }
        public DbSet<Cart> Carts { get; set; }
        ...
    }

Here is my Startup.cs

      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 framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentity<ApplicationUser, IdentityRole>()
                .AddEntityFrameworkStores<ApplicationDbContext>()
                .AddDefaultTokenProviders();

             ..........
          } 

and here is how I call my DbContext

        ApplicationDbContext storeDB = new ApplicationDbContext();

I checked my database, after doing

dotnet ef migrations add Initials
dotnet ef database update

my database has been created.  What's the complaint about then?

Thanks!

View Component binding problem

$
0
0
I invoke a view component from my razor page and pass a model property to view component I.e. (my model has a property of address details which I'm passed to view component) but the updated value from view component not updated on model to post method of controller? Kindly help me for same.

Dnu restore problems

$
0
0

Hi, I've got errors after executing dnu restore:

C:\Users\michalu.MEDIA-PRESS\UWPNext\app\UWPNext>dnu restore
Microsoft .NET Development Utility Clr-x86-1.0.0-rc2-20221

  GET https://www.nuget.org/api/v2/
  OK https://www.nuget.org/api/v2/ 780ms
Restoring packages for C:\Users\michalu.MEDIA-PRESS\UWPNext\app\UWPNext\src\UWPNext\project.json
----------
C:\Users\michalu.MEDIA-PRESS\UWPNext\app\UWPNext\src\UWPNext\project.json(0,0): Error: Microsoft.Dnx.Runtime.FileFormatException: unknown keyword platform ---> System.InvalidOperationException: unknown keyword platform
   at Microsoft.Dnx.Runtime.LibraryDependencyType.Parse(String keyword)
   at Microsoft.Dnx.Runtime.ProjectReader.PopulateDependencies(String projectPath, IList`1 results, JsonObject settings, String propertyName, Boolean isGacOrFrameworkReference)
   at Microsoft.Dnx.Runtime.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ICollection`1 diagnostics)
   at Microsoft.Dnx.Runtime.Project.TryGetProject(String path, Project& project, ICollection`1 diagnostics)
   --- End of inner exception stack trace ---
   at Microsoft.Dnx.Runtime.Project.TryGetProject(String path, Project& project, ICollection`1 diagnostics)
   at Microsoft.Dnx.Tooling.RestoreCommand.<RestoreForProject>d__69.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<>c__DisplayClass68_0.<<Execute>b__2>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Dnx.Tooling.RestoreCommand.<Execute>d__68.MoveNext()
----------
Restore failed
unknown keyword platform

NuGet Config files used:
    C:\ProgramData\NuGet\Config\Microsoft.VisualStudio.Offline.config
    C:\Users\michalu.MEDIA-PRESS\AppData\Roaming\NuGet\nuget.config

Feeds used:
    https://www.nuget.org/api/v2/
    C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

C:\Users\michalu.MEDIA-PRESS\UWPNext\app\UWPNext>dotnet restore
log  : Restoring packages for C:\Users\michalu.MEDIA-PRESS\UWPNext\app\UWPNext\src\UWPNext\project.json...
error: Unable to load the service index for source https://api.nuget.org/v3/index.json.
error:   An error occurred while sending the request.
error:   The server returned an invalid or unrecognized response

Here is a link to dropbox how it looks in VS:

https://www.dropbox.com/s/72kl0xzjsmm9yud/Capture.PNG?dl=0

Warning on upgrading BundlerMinifier.Core

$
0
0

If you start with a new ASP.NET Core project and update BundlerMinifier.Core via NuGet, you'll get a publish error

    No executable found matching command "dotnet-bundle".  

I've had to recreate my project 5 times.  I hope that I help prevent that from happening to you.

Previous version: 2.0.238 -> 2.1.258

Cookie Middleware without Core Identity

$
0
0

I'm following the directions in this article:  https://docs.asp.net/en/latest/security/authentication/cookie.html

I
get "No authentication handler is configured to handle the scheme MyCookieMiddlewareInstance.


Startup.cs :


   app.UseCookieAuthentication( new CookieAuthenticationOptions( )
   {
    AuthenticationScheme = "MyCookieMiddlewareInstance",
    LoginPath = new PathString( "/Account/Signin/" ),
    AccessDeniedPath = new PathString( "/Account/Forbidden/" ),
    AutomaticAuthenticate = true,
    AutomaticChallenge = true
   } );

.

AccountController.cs :

   var identity = new ClaimsIdentity( claims );

   var claimsPrincipal = new ClaimsPrincipal( identity );

   var authenticationProperties = new AuthenticationProperties( )
   {
    IsPersistent = true
   };

   await _httpContext.Authentication.SignInAsync( "MyCookieMiddlewareInstance", claimsPrincipal, authenticationProperties );


Any ideas?

 

ViewComponent Model binding problem

$
0
0

In my case CurrentAddress and PermanentAddress objects is null on Post Action Register of Register Controller.
kindly help me for same below are the code snap. Thanks in advance

below is Model class

public class RegisterModel
    {
        [Display(Name = "First Name")]
        public string FirstName { get; set; }

        [Display(Name = "Last Name")]
        public string LastName { get; set; }

        [Display(Name = "Current Address")]
        public AddressDetails CurrentAddress { get; set; }

        [Display(Name = "Permanent Address")]
        public AddressDetails PermanentAddress { get; set; }

    }
    public class AddressDetails
    {
        [Display(Name = "Address Line 1")]
        public string AddressLine1 { get; set; }

        [Display(Name ="Address Line 2")]
        public string AddressLine2 { get; set; }        
    }

Controller class

public class RegisterController : Controller
    {        
        public IActionResult Index()
        {
            RegisterModel model = new RegisterModel();
            model.CurrentAddress = new AddressDetails();
            model.PermanentAddress = new AddressDetails();
            return View(model);
        }

        [HttpPost]
        public IActionResult Register([FromForm]RegisterModel model)
        {
            if(ModelState.IsValid)
            {

            }
            return View("Index");
        }
    }

ViewComponent class

public class AddressViewComponent : ViewComponent
    {
        public IViewComponentResult Invoke(AddressDetails model)
        {
            return View(model);
        }
    }

ViewComponent.cshtml class

@model WebApplication6.Models.AddressDetails<div class="container"><div class="form-group">
        @Html.LabelFor(m => m.AddressLine1)
        @Html.TextBoxFor(m => m.AddressLine1, new { @class = "form-control" })</div><div class="form-group">
        @Html.LabelFor(m => m.AddressLine2)
        @Html.TextBoxFor(m => m.AddressLine2, new { @class = "form-control" })</div></div>

Register.cshtml class

Register.cshtml class
@model RegisterModel<hr /><form method="post" class="form-horizontal" asp-action="Register" asp-controller="Register"><div class="container"><div class="form-group">
            @Html.LabelFor(m => m.FirstName)
            @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" })</div><div class="form-group">
            @Html.LabelFor(m => m.LastName)
            @Html.TextBoxFor(m => m.LastName, new { @class = "form-control" })</div><div class="form-group">
            @Html.LabelFor(m => m.CurrentAddress)
            @Component.Invoke("Address", Model.CurrentAddress)</div><div class="form-group">
            @Html.LabelFor(m => m.PermanentAddress)
            @Component.Invoke("Address", Model.PermanentAddress)</div><input type="submit" value="Submit" class="btn btn-default" /></div></form>

Config Supervisor for ASP.NET Core Web APP on Linux

$
0
0

the Doc "Publish to a Linux Production Environment" on this address https://docs.asp.net/en/latest/publishing/linuxproduction.html seems out of date for the Supervisor configuration, can anyone please help to figure out how to config the Supervisor for the the asp.net core web app, because currently I always got lots of errors when I start the supervisor:

/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.Antiforgery >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.Authorization >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.Cors >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.Cryptography.Internal >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.DataProtection >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.DataProtection.Abstractions >= 1.0.0 could not be resolved.
/home/lengyanzhou168/project.json(7,41): error NU1001: The dependency Microsoft.AspNetCore.Diagnostics.Abstractions >= 1.0.0 could not be resolved.

If I directly run this web app by "dotnet run" command, it works well, only have issues when launching this web app from Supervisor.

any suggestions will be appreciated!

Viewing all 9386 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>