我目前在IdentityServer 4指南的此页面上http://docs.identityserver.io/en/dev/quickstarts/3_interactive_login.html,并且我正在尝试启动MVC应用程序。
但是,当我启动客户端应用程序时,我一直收到此错误
InvalidOperationException: Unable to resolve service for type 'IdentityServer4.Services.IIdentityServerInteractionService' while attempting to activate 'IdentityServer4.Quickstart.UI.HomeController'.
Run Code Online (Sandbox Code Playgroud)
我进入了IdentityServer4 GitHub并从那里复制了代码,但是它根本没有运行。
我不确定如何从这里继续。
这是我的Startup.cs
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace IdentityServerClient
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services) …Run Code Online (Sandbox Code Playgroud) 这是我的文件夹结构:
我目前正在尝试从位于 Areas/Applications/Views/Applications 的 Index.cshtml 文件中引用名为 _SubNavigation 的部分
但是,当我加载页面时,它没有出现。当我在检查中打开它时,它只显示链接
<partial name="~/Views/Shared/Navigation/_SubNavigation.cshtml" />
Run Code Online (Sandbox Code Playgroud)
出于某种原因,布局正在加载,但它与我的 SubNavigation 文件位于同一区域。
我有这个httpcontext声明,我想在我的视图中使用它来显示当前用户的用户名。到目前为止,这是我的操作方式:
<p>@Context.User.Claims.SingleOrDefault(u => u.Type == "UserName")</p>
Run Code Online (Sandbox Code Playgroud)
但是,结果是这样的:
用户名:user@email.com
我想念什么吗?我试图这样做:
@Context.User.Claims.SingleOrDefault(u => u.Type == "UserName").Select(c => c.Value).SingleOrDefault()
Run Code Online (Sandbox Code Playgroud)
但这不允许我在SingleOrDefault之后使用Select。
这些是我对 DinkToPDF 的设置:
var document = new HtmlToPdfDocument()
{
GlobalSettings =
{
PaperSize = PaperKind.A4,
Orientation = Orientation.Portrait,
Out = @Path.Combine(path, QuoteId + ".pdf")
},
Objects =
{
new ObjectSettings()
{
HtmlContent = result
}
}
};
converter.Convert(document);
Run Code Online (Sandbox Code Playgroud)
当我通过网络应用程序中的导航加载视图时,它会很好地显示页面。但是,当我生成 pdf 时,根本不使用引导列。相反,右列被推到底部,就像在移动视图中一样。
DinkToPDF 是否还有其他设置可以正确使用 bootstrap?
这是我的视图代码:
@model APPONE.Data.Services.ViewModels.PCVM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="@Model.HostURL/twitter-bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<link rel="stylesheet" href="@Model.HostURL/jqueryui/jquery-ui.css" />
<link rel="stylesheet" href="@Model.HostURL/theme/css/style.css" />
<link rel="stylesheet" href="@Model.HostURL/jquery-modal/jquery.modal.css" …Run Code Online (Sandbox Code Playgroud) 我目前正在学习 ASP.NET MVC,我正在学习通过其 ID 获取对象并将其引用插入到数据库中。但是,我收到此错误
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“Rentals”中的标识列插入显式值
我已经阅读并注意到有些人说要将身份插入设置为关闭,因为引用表的 ID 是自动递增的?但是我读到不推荐使用此方法,因为它显然会锁定表或仅对单个用户有用?我可以知道这样做的正确方法是什么吗?
这是我的控制器代码,它试图添加一个新的租赁
[HttpPost]
public IHttpActionResult CreateNewRental(RentalDTO RentalDTO)
{
if (RentalDTO.MovieIds.Count == 0)
{
return BadRequest();
}
var customer = _context.Customers.SingleOrDefault(c => c.Id == RentalDTO.CustomerId);
if (customer == null)
{
return BadRequest("Customer ID is not valid");
}
var movies = _context.Movies.Where(m => RentalDTO.MovieIds.Contains(m.Id)).ToList();
if (movies.Count != RentalDTO.MovieIds.Count)
{
return BadRequest();
}
foreach (var movie in movies)
{
if (movie.NumberAvailable < 1)
{
return BadRequest();
}
movie.NumberAvailable--;
var rental = …Run Code Online (Sandbox Code Playgroud) 这是我的appsettings.json。它位于没有startup.cs的类库中。我想知道是否有可能从那里获取变量以在本地使用?
{
"AccountsAddress": "http://localhost:55260/api/Accounts/",
"ApplicationUsersAddress": "http://localhost:55260/api/ApplicationUsers/"
}
public static class Manager
{
public static IConfiguration AppSetting { get; }
static Manager()
{
AppSetting = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我图书馆的结构