我试图获取本地图像文件的路径,但我无法弄清楚相对路径的位置.通常我会把它们从wwwroot/images文件夹中取出来,但是当我尝试从那里加载它时它会失败.
你在哪里获得Angular 2的相对路径?我使用generator-aspnetcore-spa来创建应用程序.
https://github.com/aspnet/JavaScriptServices
http://blog.stevensanderson.com/2016/05/02/angular2-react-knockout-apps-on-aspnet-core/
例如,在文件夹ClientApp/components/app/app.ts中.
我将把图像文件夹放在哪里,如何调用它的路径?
我有一个asp.net核心应用程序,我想对它进行一些x-unit测试.但是,当我运行我的测试时,我得到了
dotnet test
No executable found matching command "dotnet-test-"
Run Code Online (Sandbox Code Playgroud)
如何正确配置x-unit?
Project.json
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.0-rc2-final",
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
Run Code Online (Sandbox Code Playgroud) 所以我试图为我的asp.net核心应用程序实现用户登录.我在这里关注微软教程.我有两个上下文,一个叫做SchoolContext,用于保存所有与学校相关的模型,另一个叫做ApplicationDbContext,用于Account模型.这都被保存到sqlite数据库.
一切正常,直到我尝试将用户注册到我的上下文.当我尝试注册我得到的用户时,无法找到AspNetUsers表错误.如果我查看数据库,我没有看到AspNetUser表.我尝试添加迁移,但我仍然得到同样的错误.为什么没有创建表?
Startup.cs
public class Startup {
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env) {
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) {
// Add Context services
services.AddDbContext<SchoolContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("MainConnection")));
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("MainConnection")));
// Add Identify servies
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders(); …Run Code Online (Sandbox Code Playgroud) 我正在制作一个幻想游戏应用程序。现在,一个团队可以有多个球员,但也可以有多个用户(例如联赛)。当我尝试将集合添加到团队表时,出现以下错误(见下文)。我试图在线查找解决方案,看来此问题是由多对多关系引起的。但是,我不知道这怎么可能。一个团队可以有多个用户,但是一个用户只能有一个团队。解决方案是创建一个联接表,但是当我只需要让每个表上的列联接到另一个表时,为什么要在每个表上创建一个列以指向包含数据的联接表?有谁知道导致此错误的原因及其解决方法?
System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'Team.Manager' of type 'User'. Either manually configure the relationship, or ignore this property from the model. at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider) …Run Code Online (Sandbox Code Playgroud) 我的 IIS 服务器上托管了一个 ColdFusion 应用程序。我将Shibboleth服务添加到我的 Web IIS,并设置了 CGI/过滤器以使用它。我将我的应用程序添加到testshib联盟并且能够成功登录。现在我正在尝试将会话变量放入 ColdFusion 代码中。
当我转储 CGI 范围时,我看到 shibboleth 会话保存在 下HTTP_COOKIE,但它REMOTE_USER是一个空字符串。这是因为REMOTE_USER不能根据docs 使用。相反,请求标头变量应该命名为HTTP_REMOTE_USER,但我在 CGI 转储中没有看到。有没有人这是为什么?我是否必须设置我的 shibboleth 属性映射或在 ColdFusion 中?
索引.cfm
CGI dUMP
<cfdump var = "#cgi#" >
<br>HTTP_REMOTE_USER
<cfdump var="#CGI.HTTP_REMOTE_USER#">
<br>Get Request
<cfset x = GetHttpRequestData()>
<cfdump var="x">
Run Code Online (Sandbox Code Playgroud)
转储结果
HTTP_COOKIE:_shibsession_64656487474733a2f2f6465736f6d2f73686962626f6c657468=_ecb60f7e4bf7616ab3522;
Run Code Online (Sandbox Code Playgroud)
会议
Miscellaneous
Session Expiration (barring inactivity): 479 minute(s)
Client Address: 224.61.30.228
SSO Protocol: urn:oasis:names:tc:SAML:2.0:protocol
Identity Provider: https://idp.testshib.org/idp/shibboleth
Authentication Time: 2017-11-30T14:48:48.255Z
Authentication Context …Run Code Online (Sandbox Code Playgroud) 我有一个关于 SQL 连接池的问题。我的团队正在我们的节点应用程序之一中使用 knex.js 库来进行数据库查询。应用程序不时需要切换数据库。因此,我的团队创建了一个初始化函数,该函数返回配置到正确数据库的 knex 对象。然后该对象用于执行所述查询。对我来说,这似乎是多余的,并且可能会导致性能不佳,因为我们每次需要执行查询时都会启动一个 knex 对象,而不是重用单个 knex 对象。如果 knex 已经在您使用哪些数据库时执行了此操作,我可以忽略这一点(如果有人也能阐明这个问题,那就太棒了!)。此外,(这让我想到了上面的问题)连接池属性被重新定义。那么这是否意味着我们每次都会创建新的池,或者 SQL(在本例中为 SQL Sever)会重用您已经定义的连接池?这个问题可能不是 Knex 特定的,就像如果我在 C# 中使用像 knex 这样的库,并以类似的方式调用该库,SQL Server 会知道不要创建更多连接池吗?
示例代码:
/** db.js
* @param {any} database
* @returns db: Knex
*/
module.exports = ( database ) => {
var knex = require('knex')({
client: 'mssql',
connection: {
database: database,
server: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password'
},
pool: {
min: 0,
max: 10,
idleTimeoutMillis: 5000,
softIdleTimeoutMillis: 2000,
evictionRunIntervalMillis: 500
}
});
return knex;
};
Index.js
var db …Run Code Online (Sandbox Code Playgroud) 我创建了一个 Vue.js 项目,在为我的项目编写组件时使用 .vue 组件规范格式(请参见下面的示例)。我注意到,纯 JavaScript 可以导出从 vue 文件加载的这些组件。例如,index.js可以导出index.vue中定义的组件。我现在想做的是从index.js 导出多个组件。但是,当我导入多个组件时,它们不会呈现。如果我将 index.js 作为单个对象导入,然后提取组件,则它可以正常工作。为什么/如何不能从索引中提取多个组件?
索引.js
import A from './A.vue';
import B from './A.vue';
export default { A, B };
Run Code Online (Sandbox Code Playgroud)
主页.vue
<script>
import Main from "../common/forms";
const { A, B } = Main; // Works
// import { A, B } from "../common/forms"; // Not Working
export default {
name: 'app-home',
components:{ A, B}
}
</script>
<template>
<div id="app-home">
<h1>App Home </h1>
<A />
<B/>
</div>
</template>
Run Code Online (Sandbox Code Playgroud) 我有一个跟踪学校项目的应用程序.项目有科目,这些科目有任务.虽然一个项目和一个团队已经设定了领导者.学生应该轮流担任不同任务和科目的领导者(科目是我们所涵盖的不同书籍的部分).我注意到的是,在我的主题和任务的对象中,这些对象的领导者没有被加载.所以我试图在我的实体框架查询中添加一个嵌套的include,我已经在网上看到了它们,以便它们被加载.但是,当我运行我的查询时,它给了我这个错误.任何人都可以看到我做错了什么,知道如何解决这个问题?
string name = data.value;
var project = await context.Projects
.Include(p => p.Subjects)
.ThenInclude(s => s.Tasks)
.Include(p => p.Subjects.Select(s => s.Leader))
.Include(p => p.Students)
//.ThenInclude(h => h)
.Include(p => p.Leader)
.Include(p => p.Team)
.ThenInclude(t => t.Leader)
.Include(p => p.Type)
.AsNoTracking()
.FirstOrDefaultAsync(p => p.Name == name);
Run Code Online (Sandbox Code Playgroud)
Project.cs
public class Project
{
[Key]
public int ID { get; set; }
public int TypeID { get; set; }
public int? TeamID { get; set; }
public int? LeaderID { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 我创建了一个允许用户上传图像的Angular2应用程序.我想实现一个预览选项.但是,当我试图破坏它时,图像不会显示出来.我如何实现此功能?
UploadComponent.ts
import * as ng from '@angular/core';
//import { UPLOAD_DIRECTIVES } from 'ng2-uploader';
import {UploadService} from '../services/upload.service';
@ng.Component({
selector: 'my-upload',
providers:[UploadService],
template: require('./upload.html')
})
export class UploadComponent {
progress:any;
logo:any;
filesToUpload: Array<File>;
constructor(public us:UploadService){
this.filesToUpload = [];
}
upload() {
this.us.makeFileRequest("http://localhost:5000/api/SampleData/Upload", this.filesToUpload)
.then((result) => {
console.log(result);
}, (error) => {
console.error(error);
});
}
onFileChange(fileInput: any){
this.logo = fileInput.target.files[0];
}
}
Run Code Online (Sandbox Code Playgroud)
Upload.html
<h2>Upload</h2>
<input type="file" (change)="onFileChange($event)" placeholder="Upload image..." />
<button type="button" (click)="upload()">Upload</button>
<img [src]="logo" alt="Preivew">
Run Code Online (Sandbox Code Playgroud) 我有一个React Redux应用程序。我添加了实现作为CSS框架,但实现需要jquery。所以我安装了Jquery并通过npm将其添加到我的项目中。如果我这样导入jQuery
import $ from 'jquery';
Run Code Online (Sandbox Code Playgroud)
没有抛出任何错误,并且无法使用它。但仅在该组件上。所以我添加了wepback插件,这样我就可以在我的react应用程序中调用$了。但是,当我按照webpacks 网站上的说明进行操作时,出现以下错误。
Line 13: '$' is not defined
Run Code Online (Sandbox Code Playgroud)
对这是为什么有什么想法?
app.js
import React from 'react';
import '../styles/index.css';
import Header from './header/Header';
class App extends React.Component {
constructor(props){
super(props);
console.log('Application ready');
}
componentWillMount(){
$('ul.tabs').tabs();
}
render = () => (
<div>
<Header />
<div>
{this.props.children}
</div>
</div>
)
}
export default App;
Run Code Online (Sandbox Code Playgroud)
webpack.config.dev.js
alias: {
// Support React Native Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
'react-native': 'react-native-web',
jquery: "jquery/src/jquery" // What i added
// $: "jquery/src/jquery"
},
Run Code Online (Sandbox Code Playgroud)
jQuery在node_modules文件夹中,从npm安装开始,我没有将其添加到任何其他位置。
asp.net-core ×5
c# ×5
javascript ×3
angular ×2
node.js ×2
sql-server ×2
typescript ×2
asp.net ×1
cgi ×1
coldfusion ×1
iis ×1
image ×1
jquery ×1
knex.js ×1
linq ×1
reactjs ×1
saml ×1
shibboleth ×1
sqlite ×1
unit-testing ×1
vue.js ×1
vuejs2 ×1
webpack ×1
xunit ×1