我有并输入图标,看起来像这样:

<div class="input-with-icon">
<input type="text" value="abcdefeghijklmnopqrtvuvwxyz" class="form-control">
<span class="icon icon-calendar"></span>
</div>
Run Code Online (Sandbox Code Playgroud)
是否可以调整 CSS 以便输入始终适合文本宽度?例如,它会在我打字时拉伸。
目前,.input-with-icon具有固定宽度,但如果我将其设置为自动,则输入不会拉伸。
我正在尝试将XML发布到asp.net核心2:
$.ajax({
type: "POST",
url: 'api/Test',
data: "<test>hello<test>",
contentType: "application/xml",
success: function (response) { alert(response); },
});
Run Code Online (Sandbox Code Playgroud)
我应该如何编写动作,使其接受xml作为参数?
IActionResult Post([FromBody]string xml) -> xml为空IActionResult Post([FromBody]XElement xml) -> xml为空IActionResult Post(XElement xml)-> InvalidOperationException:无法创建类型为'System.Xml.Linq.XElement'的实例。模型绑定的复杂类型不能为抽象或值类型,并且必须具有无参数构造函数。IActionResult Post(string xml) -> xml为空在Startup.ConfigureServices中:
services.AddMvc()
.AddXmlSerializerFormatters();
Run Code Online (Sandbox Code Playgroud)
如何编写控制器以使其接受XML作为参数?我知道我可以从HttpContext.Request中读取它,但是我希望它可以作为参数
我想在每个单元测试中创建干净的内存数据库。当我运行多个测试时,以前测试中的数据仍保留在数据库中。如何处理现有的内存数据库?
我使用以下代码初始化每个测试:
[TestInitialize]
public void TestInitialize()
{
Services = new ServiceCollection();
Services.AddScoped<DbContextOptions<MyDbContext>>(sp => new DbContextOptionsBuilder<TacsDbContext>()
.UseInMemoryDatabase("MyTestDbContext")
.Options);
Services.AddTransient<InMemoryMyDbContext>();
Services.AddTransient<MyDbContext>(sp => sp.GetService<InMemoryTacsDbContext>());
ServiceProvider = Services.BuildServiceProvider();
}
[TestMethod]
public void Test1()
{
using (var dbContext = ServiceProvider.GetService<MyDbContext>()) ...
}
[TestMethod]
public void Test2()
{
using (var dbContext = ServiceProvider.GetService<MyDbContext>()) ...
}
Run Code Online (Sandbox Code Playgroud)
我使用.NET Core 2.0和Entity Framework Core 2.0
编辑
我无法使用标准注册:Services.AddDbContext<InMemoryMyDbContext>(...),因为
public class InMemoryMyDbContext : MyDbContext
{
public InMemoryMyDbContext(DbContextOptions<InMemoryMyDbContext> options)
: base(options) { } //compiler error
public InMemoryMyDbContext(DbContextOptions<MyDbContext> options)
: base(options) { …Run Code Online (Sandbox Code Playgroud) unit-testing entity-framework dependency-injection entity-framework-core .net-core
我正在尝试自动化 SQL 部署,包括用户和角色。当我在 Sql Management Studio 中创建用户时它可以工作,但是当我部署 dacpack 时我得到 SqlException: Login Failed for user 'MyUser'
我在本地主机上安装了 SQL Server 2016,同时启用了 Sql Server 和 Windows 身份验证。
我在 Visual Studio 中有包含这些文件的 Sql 数据库项目:
MyUser.sql [构建操作=构建]
CREATE USER [MyUser] WITH Password='$(MyUserPassword)';
Run Code Online (Sandbox Code Playgroud)RolesMembership.sql [构建动作=构建]
ALTER ROLE [db_datareader] ADD MEMBER [MyUser]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [MyUser]
Run Code Online (Sandbox Code Playgroud)我构建它并使用命令行部署创建的 dacpac:
SqlPackage.exe /Action:Publish
/SourceFile:"MyDatabase.dacpac"
/Profile:"MyDatabase.publish.xml"
/v:MyUserPassword=c2Aaaaaaaaaaaa`
Run Code Online (Sandbox Code Playgroud)当我在 sql management studio 中执行此脚本时,它会起作用。但是当我使用 SqlPackage 部署它时,它会导致
SqlException: 用户“MyUser”登录失败
编辑:
我调查了生成的 sql 脚本,其中包括REVOKE CONNECT:
CREATE USER [MyUser] …Run Code Online (Sandbox Code Playgroud) sql-server database-project dacpac sqlpackage sql-server-2016
我正在使用 webclient 从 sharepoint 在线下载 XML 文件。
但是,当我使用WebClient.DownloadString(string url)方法时,某些字符未正确解码。
当我使用WebClient.DownloadFile(string url, string file)然后读取文件时,所有字符都是正确的。
xml 本身不包含编码声明。
string wrongXml = webClient.DownloadString(url);
//wrongXml contains Ä™ instead of ?
webClient.DownloadFile(url, @"C:\temp\file1.xml");
string correctXml = File.ReadAllText(@"C:\temp\file1.xml");
//contains ?, like it should.
Run Code Online (Sandbox Code Playgroud)
此外,当在 Internet Explorer 中打开 url 时,它会正确显示。
这是为什么?是因为我的机器上的默认 Windows 编码或 web 客户端在使用 DownloadString 或 DownloadFile 时处理响应的方式不同吗?
在 docker-compose.yml 中,
以下端口符号有什么区别?
ports:
- "5000:5000"
Run Code Online (Sandbox Code Playgroud)
回复:
ports:
- "8080"
Run Code Online (Sandbox Code Playgroud)
或者根本没有端口。
例如,在下面的 docker-compose.yml 中,mongodb 服务必须公开一个端口来与节点服务通信,但没有指定端口
services:
node:
build:
context: .
dockerfile: node.dockerfile
ports:
- "3000:3000"
networks:
- nodeapp-network
depends_on:
- mongodb
mongodb:
image: mongo
networks:
- nodeapp-network
networks:
nodeapp-network:
driver: bridge
Run Code Online (Sandbox Code Playgroud)
来源: https: //github.com/DanWahlin/NodeExpressMongoDBDockerApp
然而,在这些 docker-compose.yml 中,有使用27017:27017或8080符号指定的端口 awlay。
services:
nginx:
container_name: nginx
image: ${DOCKER_ACCT}/nginx
build:
context: .
dockerfile: .docker/nginx.${APP_ENV}.dockerfile
links:
- node1:node1
- node2:node2
- node3:node3
ports:
- "80:80"
- "443:443"
networks:
- codewithdan-network
node1: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将从函数返回的值分配给变量,但该变量仍然为空。为什么?
function Foo{
Param([string]$key,
[system.collections.generic.dictionary[string,system.collections.arraylist]] $cache)
if (-not $cache.ContainsKey($key))
{
$cache[$key] = New-Object 'system.collections.arraylist'
}
$result = $cache[$key]
return $result #when debugging, this is not null
}
$key = ...
$cache = ...
#EDIT: $result = Foo ($key, $cache)
#Im actually calling it without comma and bracket:
$result = Foo -key $key -cache $cache
$result.GetType()
#results in: You cannot call a method on a null-valued expression.
#At line:1 char:1
#+ $result.GetType()
Run Code Online (Sandbox Code Playgroud) 我想通过仅选择两种类型中都存在的成员来创建类型:
interface A {
X: number;
Y: number;
}
interface B {
Y: number;
Z: number;
}
type C = Common<A, B>; // { Y: number; }
Run Code Online (Sandbox Code Playgroud)
是否有内置的实用程序类型、命题或常用模式来实现此目的?
注意:我能够编写以下实用程序类型,但我认为很难推理
type Common<T1, T2> = Omit<T1, keyof Omit<T1, keyof T2>>
Run Code Online (Sandbox Code Playgroud)
然而,有没有什么
如何配置 BlazorHub 端点以要求经过身份验证的用户在未经过身份验证的情况下自动重定向登录?
我已尝试配置默认授权策略以及调用RequireAuthenticatedBlazorHub 端点生成器,但当我运行 Blazor 应用程序时,我仍然没有重定向到登录页面。
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(); // added by me
services.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
}); // added by me
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 …Run Code Online (Sandbox Code Playgroud) c# authentication blazor blazor-server-side asp.net-core-5.0
我正在使用以下步骤来执行解决方案级别缓存:
- task: Cache@2
inputs:
key: 'nuget | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/packages.lock.json'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: $(NUGET_PACKAGES)
displayName: Cache NuGet packages
- task: DotNetCoreCLI@2
displayName: 'dotnet restore using package.lock.json'
inputs:
command: 'restore'
restoreArguments: '--locked-mode'
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
Run Code Online (Sandbox Code Playgroud)
但是,其中Post-job: Cache NuGet packages有警告:
##[警告]给定的缓存键在恢复和保存步骤之间的解析值已更改
我意识到这是因为在解析密钥时还选择了复制到输出目录 */bin/release/net5.0/packages.lock.json 文件的锁定文件。
我该如何解决这个问题?
.net ×2
c# ×2
.net-5 ×1
.net-core ×1
ajax ×1
asp.net-core ×1
azure-devops ×1
blazor ×1
css ×1
dacpac ×1
docker ×1
nuget ×1
powershell ×1
sql-server ×1
sqlpackage ×1
typescript ×1
unit-testing ×1
webclient ×1
xml ×1