我知道clear'清除'当前屏幕的命令,但它只是通过打印许多换行来实现这一点 - 清除的内容只是向上滚动.
有没有办法彻底擦除终端的所有先前输出,以便即使向上滚动也无法到达它?
我在本地克隆了ASP.NET Core SignalR Repo,并尝试在以下环境中打开解决方案.
IDE
Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01055
Run Code Online (Sandbox Code Playgroud)
DOT NET CLI
? dotnet --info
.NET Command Line Tools (1.0.0-preview2-1-003177)
Product Information:
Version: 1.0.0-preview2-1-003177
Commit SHA-1 hash: a2df9c2576
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Run Code Online (Sandbox Code Playgroud)
我最终看到了很多这类错误消息:
..\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj:error:项目的默认XML名称空间必须是MSBuild XML名称空间.如果项目是以MSBuild 2003格式创作的,请添加xmlns="http://schemas.microsoft.com/developer/msbuild/2003"到元素中.如果项目是以旧的1.0或1.2格式编写的,请将其转换为MSBuild 2003格式...\Repos\SignalR\src\Microsoft.AspNetCore.SignalR\Microsoft.AspNetCore.SignalR.csproj
我想知道如何以正确的方式解决这个问题.
msbuild asp.net-mvc visual-studio-2015 .net-core asp.net-core
我注意到如果我写的东西如下:
static void Main(string[] args)
{
const const const bool flag = true;
}
Run Code Online (Sandbox Code Playgroud)
编译器不会警告我多个consts.所以这似乎模仿C修饰符,因为它们是幂等的.
但是,如果我写:
private readonly readonly int a;
Run Code Online (Sandbox Code Playgroud)
编译器确实警告我重复readonly.
那么这里发生了什么?修饰语是否是幂等的?
csc版本1.0.0.50618
我是ASP.Net MVC的新手,现在尝试使用内置的用户登录功能.我可以在注册视图中注册用户.如果我尝试使用创建的用户登录,这也有效.我被重定向到母版页.
但是我无法获得当前用户的UserID.我在HomeController和AccountController中尝试了我的代码,但两者都没有用.第一行中的语句返回null.
var userID = User.Identity.GetUserId();
if (!string.IsNullOrEmpty(userID))
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(ApplicationDbContext.Create()));
var currentUser = manager.FindById(User.Identity.GetUserId());
}
Run Code Online (Sandbox Code Playgroud)
在获取UserID之前,我是否需要做其他事情?
我很熟悉将appsettings.json部分加载到.NET Core startup.cs中的强类型对象中.例如:
public class CustomSection
{
public int A {get;set;}
public int B {get;set;}
}
//In Startup.cs
services.Configure<CustomSection>(Configuration.GetSection("CustomSection"));
//Inject an IOptions instance
public HomeController(IOptions<CustomSection> options)
{
var settings = options.Value;
}
Run Code Online (Sandbox Code Playgroud)
我有一个appsettings.json部分,其键/值对随着时间的推移会在数量和名称上有所不同.因此,对类中的属性名称进行硬编码是不切实际的,因为新的键/值对需要在类中进行代码更改.一些键/值对的小样本:
"MobileConfigInfo": {
"appointment-confirmed": "We've booked your appointment. See you soon!",
"appointments-book": "New Appointment",
"appointments-null": "We could not locate any upcoming appointments for you.",
"availability-null": "Sorry, there are no available times on this date. Please try another."
}
Run Code Online (Sandbox Code Playgroud)
有没有办法将此数据加载到MobileConfigInfo Dictionary对象中,然后使用IOptions模式将MobileConfigInfo注入控制器?
我正在尝试使用授权代码流实现带有AspNet Core的Identity Server 4.
问题是,github上的IdentityServer4存储库有几个样本,但没有一个带有授权代码流.
有没有人有关于如何使用Identity Server 4和MVC中的客户端实现授权代码流的示例?
刚切换到VS2022,创建新项目,看到这个:
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Run Code Online (Sandbox Code Playgroud)
所有其他东西在哪里?为什么现在默认了?
按照Visual Studio代码文档中描述的步骤,dnx . kestrel在Mac OS X上通过VSCode的命令调色板运行最终命令会在访问http:// localhost:5001时导致IOException :
kqueue() FileSystemWatcher has reached the maximum nunmber of files to watch.
Run Code Online (Sandbox Code Playgroud)
有关完整的堆栈跟踪,请参阅附带的屏幕截图.可能有什么不对?
根据我的理解,为ASP Dotnet Core 2预览1/2设置监听端口的正确方法是在appsettings.json中创建一个Kestrel部分,格式如下:
"Kestrel": {
"EndPoints": { //Could also be Endpoints, it's a bit unclear
"Http": {
"Address": "127.0.0.1",
"Port": 9001 //the port you want Kestrel to run on
},
Run Code Online (Sandbox Code Playgroud)
我试图在Debian机器上设置示例webapp,但是当我启动应用程序时,它写出应用程序在端口5000上列出,默认端口..
我知道appsettings.json被读取,因为当我将日志记录级别更改为Trace时,我在启动时获得更多信息,包括没有找到端点,应用程序将使用标准5000端口.
我试图在Github上搜索aspnet源代码,我可以找到一个从配置中读取Kestrel部分的区域(https://github.com/aspnet/Identity/blob/e38759b8a2de1b7a4a1c19462e40214b43c1cf3b/samples/IdentityOIDCWebApplicationSample/MetaPackage/KestrelServerOptionsSetup .cs),但你可以看到它看起来像一个示例项目.
我缺少什么,这不是在ASP Dotnet核心2中配置Kestrel的标准方法吗?
我试图将依赖注入我的中间件构造函数,如下所示
public class CreateCompanyMiddleware
{
private readonly RequestDelegate _next;
private readonly UserManager<ApplicationUser> _userManager;
public CreateCompanyMiddleware(RequestDelegate next
, UserManager<ApplicationUser> userManager
)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
await _next.Invoke(context);
}
}
Run Code Online (Sandbox Code Playgroud)
我的Startup.cs文件看起来像
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(Configuration.GetConnectionString("IdentityConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
...
app.UseMiddleware<CreateCompanyMiddleware>();
...
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
启动应用程序时发生错误.InvalidOperationException:无法从根提供程序解析作用域服务'Microsoft.AspNetCore.Identity.UserManager`1 [Common.Models.ApplicationUser]'.Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(类型serviceType,IServiceScope范围,IServiceScope rootScope)