asp.net-core-2.0

How to load partial razor page into razor view

♀尐吖头ヾ 提交于 2019-12-11 17:22:21
问题 I am trying to replace my view components with razor pages but it seems that it's not possible to load a partial razor page because a model is expected to be passed yet it is my understanding that the model for a razor page should be declared in the OnGetAsync method. Here is my code... Razor Page @page "{id:int}" @model _BackgroundModel <form method="POST"> <div>Name: <input asp-for="Description" /></div> <input type="submit" /> </form> Razor Page Code-Behind public class _BackgroundModel :

Using DB Context in a Custom Validation Attribute

断了今生、忘了曾经 提交于 2019-12-11 16:53:20
问题 I am trying to create a valdiation attribute in my Core 2 project. It needs to validate the value against a list of existing values held in the database. The code below isn't working, it isn't able to access the DB Context. Any ideas why/how to correct? public class BibValidatorAttribute : ValidationAttribute { protected override ValidationResult IsValid( object value, ValidationContext validationContext) { RaceEntryViewModel raceEntry = (RaceEntryViewModel)validationContext.ObjectInstance;

How to integrate Quartz.Net jobs that require “scoped” services injected in them (ASP.NET Core 2.0)?

冷暖自知 提交于 2019-12-11 16:41:38
问题 I am trying to create some Quartz.Net jobs following my own answer from this question. However, if the job is fairly complex and required "scoped" ( services.AddScoped<.., ...> ) services, the example does not work because jobs are created as singletons. If I change them to be scoped, the serviceProvider does not contain the services I need. I have managed to make it work using the following code: Startup.cs /// <summary> /// service provider to be used by qiaryz job factory which cannot use

Azure Cosmos DB - CreateDatabaseAsync - Resource Not Found

☆樱花仙子☆ 提交于 2019-12-11 16:39:51
问题 I have been developing an application with Azure Cosmos DB using the Emulator with good success - I've been able to create the database & collections and add documents to the collections as well as read those documents. the trouble now is that I've tried to swap the emulator out for a live instance of Azure Cosmos DB and I am getting an error whilst trying to create the database. Microsoft.Azure.Documents.DocumentClientException: Entity with the specified id does not exist in the system. note

Url.Action in asp.net core

╄→гoц情女王★ 提交于 2019-12-11 16:20:48
问题 I like the new tag helpers attributes which make readable dynamic html contents. I can create a link by using the asp-controller and asp-action attributes like this: <a asp-controller="Home" asp-action="Index">Index</a> The problem is that there are cases where I need just the URL of the action in order to use it my javascript. For example in order to make an ajax call in ASP.NET MVC 5, I could have the following code: $.ajax({ type: "POST", url: '@Url.Action("GetData","Ajax")', data: "{ }",

How to have custom validation of a JWT bearer token early in the pipeline

巧了我就是萌 提交于 2019-12-11 16:12:46
问题 I have in incoming bearer token that has an incorrect audience. There is enough information in the token via other claims that prove what the audience should be. I was hoping to fix it up early so that I could still take advantage of the JwtBearerOptions.TokenValidationParameters.ValidateAudience = true; JwtBearerOptions.TokenValidationParameters.ValidAudiences ={"the right one"}; I can hook the OnTokenValidated event, and rewrite the principal, but that is too late. Earlier in the pipeline

Multi-tenant authentication, IMustHaveTenant entity in ASP.NET Boilerplate Module Zero

假如想象 提交于 2019-12-11 16:04:19
问题 Multi-Tenant Authentication I have created a new tenant from the swagger UI as an admin and I can check in the data the tenant created successfully together with admin account . Now how do I login as the admin of the newly created tenant? Cos I tried Token-authenticating via Postman, specifying tenancyName in the request body and it only seems to authenticate the admin from default tenant - even when I put in rubbish in the tenancyName field, it won't detect any error or exception. I check

How to Configure WebpackDevServer to run an app with ASP.NET CORE 2.0 IISEXPRESS

倖福魔咒の 提交于 2019-12-11 15:38:37
问题 Using the ASP.NET Core 2.0 template for creating react app with redux i want to use the webpack-dev-server which is used in the react CRA (CREATE REACT APP) . The ASP.NET Core 2.0 app build outputs to a js (Client/Server) file and renders it on a razor page. (cshtml ) (SSR) which on run (F5) runs using the IISEXPRESS. I want to run the same using IISEXPRESS but using the WebpackDevServer since the execution in it faster especially after the initial build . I have tried the following by adding

ViewData & Model does not exist in the current context

假如想象 提交于 2019-12-11 15:13:38
问题 I have a .Net Core 1.1 project using VS 2017 EF Core. When I created a new view, I received the does not exist in current context error on the ViewData, the Model, and even the @model. In trying to fix the problem, I ended up updating my packages which only gave me more errors to resolve. I'm not running .Net Core 2.0 because of the update. The other views in my project are not having this issue. I created only one other view and I ended up having the same problem with it, but just on @model

Get the Domain or Host name and Port in Configure of Startup.cs

女生的网名这么多〃 提交于 2019-12-11 12:47:25
问题 I'm in need of help in getting the host/domain name and port of my application. So far, here's my sample code in my Configure method inside the Startup.cs : public void Configure(IApplicationBuilder app, IHostingEnvironment env) { var url = ""; // something that will get the current host/domain and port of the running applicaiton. RecurringJob.AddOrUpdate<ISomething>(i=>i.SomethingToExecute(url), Cron.Daily); } Because I need to pass the url string to my SomethingToExecute method public class