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

AspNetCore and IIS Authentication Type

$
0
0

Good day

I have this scenario regarding our websites at work where we deploy our applications. One of these websites must be accessible from both inside the network and outside the network. The people accessing it from outside will not be out network users in most cases.

On our QA server the site is configured to be accessible from outside the network. But on IIS, the site is configured to Windows Authentication type. When trying to access it from outside the network, it pops-up the network credentials form (so that a user can submit their network credentials) before accessing the site.

This is not practical for the non-network users. And the reason this is happening is because of the Windows Authentication type. I have tried to convince my superiors that this must change to Anonymous Authentication (this works fine). But they are not budging. They say this is not secure. Some digging on the internet suggest to use FormsAuth. However, this authentication type is not compatible with AspNetCore.

I am not sure if you have encountered something like this. Or if you can point us to some direction. My conclusion at the moment is that this is not possible Windows Authentication and only possible with Anonymous Authentication.

Any advice will help us.

Thanks


Hosting ASP.NET Core on public domain issue.

$
0
0

Our ASP.NET Core 1.1 website is deployed on IIS on Windows Server 2012 R2 on a public domain. We can access it internally from our company network. But not from out side world. Our IT department think they have their configuration right and the issue may have something to do with the ASP.NET Core web application configuration. We can not think of anything on ASP.NET application configuration that would block its access from outside company network. Any thoughts?

UPDATE:

When we access EXACT same url from outside company network the browser, after few seconds, displays the following message (no http error). 

  • IE: This page can not be displayed
  • Chrome:  This site can’t be reached

On F12 (both IE and Chrome), Console and network tabs show no error

APIs throwing CORS error from one web server but are accessible from another domain (Both are in different domains).

$
0
0

Hello All,

        I have created a web API in the asp.Net core and enabled cors in the startup.cs file. After deployment windows server APIs are accessible via AJAX from another domain. But when I am hosting the APIs on another windows server it is throwing the following error:-

"Failed to load http://someDomian/api/APIName: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:57515, *', but only one is allowed. Origin 'http://localhost:57515' is therefore not allowed access."

I am wondering why APIs are giving errors on one web server while they are accessible from another web server.

Thanks in advance

Can we use OWIN to Host Asp.net Core Web API

$
0
0

Hello ALL,

i am just started into ASP.NET CORE. I need some help to host a API which is built on asp.net core using OWIN. 

I was able to host API into windows service for API built on asp.net frame work by following http://blog.thedigitalgroup.com/amitd/2016/02/24/self-hosting-webapi-2-using-owin/ .

But i am unable to do so for API's built on asp.net core. I need the logic in owinconfiguration class (in windows service project) to call startup class ( in core project). In the above link , since api were built on asp.net , webapi config file was used. But  in the new asp.net core web application template we dont have such config files..

Local Database Realtime

$
0
0

Hi folks,
I am using Asp.net core and Angular 4. I want Database real time e.g Notification. Should I use SignalR or Interval time? What do you prefer?

I am waiting for your response.
Thanks in advance! :)

Roles and RoleManager in ASP.NET Core 2

$
0
0

My next step in this journey is to create some roles and a simple user.  Unfortunately, I get an error regarding my tables not having primary keys as shown below.  I don't understand how to fix it.  I think this should be really simple, I should just get an instance of a role manager, and then just add a role, so I am really surprised by this.  Unfortunately, the error message is saying that the IdentityUserLogin<Guid> doesn't have a primary key.  When I look in OnModelCreate, there is a Key entry for that table, so I am not sure what is going on.  Any help is appreciated.

Specifically, the exception happens on:

var roleExists = roleTask.Result;

TIA


I am trying to use the following code in my Startup's ConfigureServices method:
// Build the intermediate service provider
var serviceProvider = services.BuildServiceProvider();

//resolve implementations
var dbContext = serviceProvider.GetService<PoopTheWorldContext>();
var _context = new PoopTheWorldContext(
serviceProvider.GetRequiredService<DbContextOptions<PoopTheWorldContext>>());
var userManager = serviceProvider.GetService<UserManager<ApplicationUser>>();
var roleManager = serviceProvider.GetService<RoleManager<ApplicationRole>>();
var roleTask = roleManager.RoleExistsAsync("Administrator");
var roleExists = roleTask.Result;

Exception:
System.AggregateException occurred
HResult=0x80131500
Message=One or more errors occurred. (The entity type 'IdentityUserLogin<Guid>' requires a primary key to be defined.)
Source=<Cannot evaluate the exception source>
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at PooperApp.Startup.ConfigureServices(IServiceCollection services) in C:\Users\wallym\Documents\Visual Studio 2017\Projects\PooperApp\PooperApp\Startup.cs:line 91

Inner Exception 1:
InvalidOperationException: The entity type 'IdentityUserLogin<Guid>' requires a primary key to be defined.

I check out my OnModelCreating, and I see a key definition for IdentityUserLogin.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AspNetRoleClaims>(entity =>
{
entity.HasIndex(e => e.RoleId);

entity.HasOne(d => d.Role)
.WithMany(p => p.AspNetRoleClaims)
.HasForeignKey(d => d.RoleId);
});

modelBuilder.Entity<AspNetRoles>(entity =>
{
entity.HasIndex(e => e.NormalizedName)
.HasName("RoleNameIndex")
.IsUnique()
.HasFilter("([NormalizedName] IS NOT NULL)");

entity.Property(e => e.Id).ValueGeneratedNever();

entity.Property(e => e.Name).HasMaxLength(256);

entity.Property(e => e.NormalizedName).HasMaxLength(256);
});

modelBuilder.Entity<AspNetUserClaims>(entity =>
{
entity.HasIndex(e => e.UserId);

entity.HasOne(d => d.User)
.WithMany(p => p.AspNetUserClaims)
.HasForeignKey(d => d.UserId);
});

modelBuilder.Entity<AspNetUserLogins>(entity =>
{
entity.HasKey(e => new { e.LoginProvider, e.ProviderKey });
entity.HasIndex(e => e.UserId);

entity.HasOne(d => d.User)
.WithMany(p => p.AspNetUserLogins)
.HasForeignKey(d => d.UserId);
});

modelBuilder.Entity<AspNetUserRoles>(entity =>
{
entity.HasKey(e => new { e.UserId, e.RoleId });

entity.HasIndex(e => e.RoleId);

entity.HasOne(d => d.Role)
.WithMany(p => p.AspNetUserRoles)
.HasForeignKey(d => d.RoleId);

entity.HasOne(d => d.User)
.WithMany(p => p.AspNetUserRoles)
.HasForeignKey(d => d.UserId);
});

modelBuilder.Entity<AspNetUsers>(entity =>
{
entity.HasIndex(e => e.NormalizedEmail)
.HasName("EmailIndex");

entity.HasIndex(e => e.NormalizedUserName)
.HasName("UserNameIndex")
.IsUnique()
.HasFilter("([NormalizedUserName] IS NOT NULL)");

entity.Property(e => e.Id).ValueGeneratedNever();

entity.Property(e => e.Email).HasMaxLength(256);

entity.Property(e => e.NormalizedEmail).HasMaxLength(256);

entity.Property(e => e.NormalizedUserName).HasMaxLength(256);

entity.Property(e => e.UserName).HasMaxLength(256);
});

modelBuilder.Entity<AspNetUserTokens>(entity =>
{
entity.HasKey(e => new { e.UserId, e.LoginProvider, e.Name });

entity.HasOne(d => d.User)
.WithMany(p => p.AspNetUserTokens)
.HasForeignKey(d => d.UserId);
});
}

enable async / parallel calls to aspnet core web api

$
0
0

hi, 

Ihow to do i enable aspnet core web api to be async and parallel ? 

i've methods in controller which are marked async and task but it does not enable parallel calls from javascript , 

should i have to make changes in startup .cs to enable aprallel calls to controller ?

or make it async 

here is a sample ofmy controller 

<div class="line number2 index1 alt1"></div> <div class="line number2 index1 alt1"></div> <div class="line number2 index1 alt1">


[httppost]
public async Task<IActionResult> City(string city)
{
using (var client = new HttpClient())
{

}
return data
}

[httppost]
public async Task<IActionResult> welcome(string city)
{
using (var client = new HttpClient())
{
}
reutrn data
}

</div> <div class="line number5 index4 alt2">i've sismiarly another method as the same </div> <div class="line number5 index4 alt2"></div> <div class="line number5 index4 alt2"></div>

Seed Data Sort

$
0
0

Hi folks,

I have created Seed data as below:

        var subModules = new SubModule[]
            {
                new SubModule{ ModuleID=1, Name="***" },
                new SubModule{ ModuleID=1, Name="***" },
                new SubModule{ ModuleID=1, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=2, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=3, Name="***" },
                new SubModule{ ModuleID=4, Name="***" },
                new SubModule{ ModuleID=4, Name="***" },
                new SubModule{ ModuleID=4, Name="***" },
                new SubModule{ ModuleID=5, Name="***" },
                new SubModule{ ModuleID=5, Name="***" },
                new SubModule{ ModuleID=5, Name="***" },
                new SubModule{ ModuleID=5, Name="***" },
                new SubModule{ ModuleID=6, Name="***" },
                new SubModule{ ModuleID=6, Name="***" },
                new SubModule{ ModuleID=6, Name="***" },
				........
            };

            foreach (SubModule item in subModules)
            {
                context.SubModules.Add(item);
            }
            context.SaveChanges();



After run the project, It goes into a table. It seems ok but i want sort (Ascending order) of module id. Any idea?
I am waiting for your response.
Thanks in Advance!


VS 2017 - Custom scaffolder

$
0
0

Hi,

I would like to create, Under VS2017, custom scaffolder to automatically create resources file associated with a view page when i create new razor page ?

Something like the view created when with create controler MVC with views using EF

Do you know how can i achieve this ?

Unable to scaffold a new controller with Entity Framework Core in ASP.Net Core 2.0

$
0
0

I'm not 100% sure this has to do with ASP.Net Core, but think so.

I'm going over this tutorial on ASP.Net core , and am using VS 2017 to do so-- https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db

In so doing, I can get to the point where it asks me to scaffold a new controller using EF, at which point I get told "There was an error running the selected code generator: 'No parameterless constructor defined for this object'."

Sure enough, my generated DBContext class does not have a parameterless constructor.  Instead, it reads like so:

 public partial class Northwind_v1Context : DbContext
    {
        public Northwind_v1Context(DbContextOptions<Northwind_v1Context> options) : base(options)
        {
        }

        public virtual DbSet<Categories> Categories { get; set; }
        public virtual DbSet<CategoryLang> CategoryLang { get; set; }
        public virtual DbSet<CustomerCustomerDemo> CustomerCustomerDemo { get; set; }
//etc

Is there something I'm doing wrong, and/or is there a workaround?

ASP Core 2.0 Visual Studio and Tooling

$
0
0

I'm implementing a new ASP Core 2.0 project.  I was planning on using Bower but then I read the following on theBower home page.

...psst! While Bower is maintained, we recommend using Yarn and Webpack for front-end projects read how to migrate!

I have to admit, the JavaScript tooling world is a little confusing since most of my experience has been the .NET stack.  I get Bowser,  Bower is like NuGet but it seems Yarn and WebPack are not at all like Bowser or NuGet.   Can anyone point me to some docs or help fill in the holes.

Asp.net core with client-sde c#

$
0
0

After all the efforts by Microsoft to keep .Net alive on the web by creating asp.net core, it was strongly expected and still strongly expected from Microsoft to develop a formal compiler from .Net to javascirpt (similar to JSIL)  for asp.net core client-side events rather than relying on third party scripts such AngularJS etc...

ASP .NET Core 2.0.2 - When ?

asp-page-handler how to load content in @RenderBody if the a tag is in a nav bar outside ?

$
0
0

Hi,

I have a nav tag from bootstrap and the div below with @RenderBody.

Inside the nav I have the <a asp-page-handler... Once clicked the content loads inside the nav and I can understand the reason.  but I'm looking for the way to load the content in the @RenderBody which is in the div below the nav tag.

High Speed/ Efficient (Quick response or highly available) Application

$
0
0

Hi,

I am developing an application in MVC Core.

Now I have some concerns.

I want to develop such high efficient/quick application and the response time of this application will be highest Efficient.

I want something like (ebay or amazon high response/quick/efficient applications) 

Now what are my choices to develop such application?

As per my current knowledge,  I know the following things :

1). I should use Asynchronous.

2).  I should use Signal R

3). I should use optimized/well structured code

4). I should parallel programming

5). What else I can do ?

6). Adding more servers / on Clouds (through cloud computing) 

7). Making more Logic on database side for the database efficiency (through stored procedures).  

8). What if I use Angular 4 ? (Will it enhance something in performance or will just improves the powerful UI bindings ?)

Please guide .

It will be really appreciated if some experts will share their opinion or solution about this.


An unhandled exception occurred while processing the request.

$
0
0

Hi i start learning dot net core.

When i create a new project in Visual Studio Code, I try running the project but I got the following erorr

"InvalidOperationException: The layout view '~/Views/Shared/_Layout.cshtml' could not be located. The following locations were searched:
~/Views/Shared/_Layout.cshtml"

Here is the _Layout.cshtml

<!DOCTYPE html><html><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>@ViewData["Title"] - MVCProject</title><environment include="Development"><link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /><link rel="stylesheet" href="~/css/site.css" /></environment><environment exclude="Development"><link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/css/bootstrap.min.css"
              asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" /><link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" /></environment></head><body><nav class="navbar navbar-inverse navbar-fixed-top"><div class="container"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a asp-area="" asp-controller="Home" asp-action="Index" class="navbar-brand">MVCProject</a></div><div class="navbar-collapse collapse"><ul class="nav navbar-nav"><li><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li><li><a asp-area="" asp-controller="Home" asp-action="About">About</a></li><li><a asp-area="" asp-controller="Home" asp-action="Contact">Contact</a></li></ul></div></div></nav><div class="container body-content">
        @RenderBody()<hr /><footer><p>&copy; 2017 - MVCProject</p></footer></div><environment include="Development"><script src="~/lib/jquery/dist/jquery.js"></script><script src="~/lib/bootstrap/dist/js/bootstrap.js"></script><script src="~/js/site.js" asp-append-version="true"></script></environment><environment exclude="Development"><script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js"
                asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"
                integrity="sha384-K+ctZQ+LL8q6tP7I94W+qzQsfRV2a+AfHIi9k8z8l9ggpc8X+Ytst4yBo/hH+8Fk"></script><script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/bootstrap.min.js"
                asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
                crossorigin="anonymous"
                integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"></script><script src="~/js/site.min.js" asp-append-version="true"></script></environment>

    @RenderSection("Scripts", required: false)</body></html>

And here is the _ViewStart.cshtm

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

Please show me the way to fix it

Entity Framework 6 and .NET Standard 2.0

$
0
0

Is Entity Framework 6 usable in .NET Standard 2.0?

setting Reply URL and Correlation error

$
0
0

I have Core Web app in a Service Fabric service running, single node.  It uses AzureAD for authentication. This works fine, the AzureApp hashttps://localhost:12345/signin-oidc  as reply Url defined and the app is running on that port. 

Now we modified this service, allowing it to run on multiple nodes and without a fixed port number. So it is running on 5 nodes under different port numbers. And we do not really know up front what portnumbers. We have another node that acts as a gateway and it is running on and https://localhost:12345 and forwards the requests to the other 5 nodes.

The problem is that after the user logged in in Azure we get an error like 

AADSTS50011: The reply address 'http://localhost:31001/signin-oidc' does not match the reply addresses configured for the application: xxxxxxxxxxxxxxxxxxx'. 

So how can we set the Reply URL to a fixed value? 

I was expecting I could do something with the OnRedirectToIdentityProvider event, but it is never reached. 

Surprising as the documentation states 'Invoked before redirecting to the identity provider to authenticate', I would expect to hit it BEFORE I go to the login page.

Thanks

  Ben

 

</div>

default asp.net core web app template fails to run

$
0
0

Using asp.net core 2.0 with Visual Studio Community 2017 for Mac

Created a brand new asp.net core web app project using the provided template

Click run project 

Project builds successfully 

Browser opens and shows message:  Safari Cannot Open The Page - Safari cannot open the page localhost:5001 because the server unexpectedly dropped the connection

In Visual Studio Community IDE the Program.cs file loads with  BuildWebHost(args).Run(); highlighted

Click continue button in IDE brings up a Program Report for dot net - dot net quit unexpectedly 

Note that the asp.net core empty template runs without an issue

Process Failure 502.5 when trying to call Web API hosted on Windows Server 2012 R2

$
0
0

I have created an ASP.Net Core 2.0 Web Api. It works perfectly in Visual Studio. But when I deploy it to Windows Server 2012 R2, I get the following error when I try to call any of its endpoints:

HTTP Error 502.5 - Process Failure

In Chrome's console, there is no extra info. However, in Edge's console, it says:

HTTP502: BAD GATEWAY - The server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. GET - http://eball.propworx.co.za/api/values

On the Event Viewer, this error gets logged twice:

Application 'MACHINE/WEBROOT/APPHOST/EBALL' with physical root 'C:\inetpub\wwwroot\eball\' failed to start process with commandline ' ', ErrorCode = '0x80070057 : 0.

I've spents HOURS on this, and read dozens of web pages. From all I've read, I have set the .NET CLR version to "No Managed Code" in the application pool's basic settings. I have also set "Load User Profile" to "True" in the advanced settings. I have also installed the "Microsoft .NET Core 2.0.0 - Windows Server Hosting" package, and have installed all the latest Windows updates. If I run the API directly from the command prompt by executing "dotnet eball.dll" it runs perfectly and I can call the API's endpoints via http://localhost:5000:

This is the Web.config file that Visual Studio generates when it deploys the app (via FTP) 

<?xml version="1.0" encoding="utf-8"?><configuration><system.webServer><handlers><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" /></handlers><aspNetCore processPath="dotnet" arguments=".\eBall.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" /></system.webServer></configuration><!--ProjectGuid: ccf466e4-3193-4fa6-9140-04b89af4c0fc-->

And this is the project's .csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web"><PropertyGroup><TargetFramework>netcoreapp2.0</TargetFramework><UserSecretsId>8c10401b-bfc2-46d0-9799-2cda71ff5cb1</UserSecretsId></PropertyGroup><ItemGroup><Folder Include="Data\" /><Folder Include="Models\" /><Folder Include="Views\Shared\" /><Folder Include="wwwroot\" /><Folder Include="wwwroot\css\" /><Folder Include="wwwroot\images\" /><Folder Include="wwwroot\js\" /></ItemGroup><ItemGroup><PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /><PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" /></ItemGroup><ItemGroup><DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /></ItemGroup></Project>

Any ideas anyone? I'm at my wits end... Thank you... :(

Viewing all 9386 articles
Browse latest View live


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