我们正在使用msdeploy(或Web部署,如果您愿意)打包和部署Web应用程序.通过声明参数包时间,我们可以在部署时提供值(以替换连接字符串等).
我们目前面临的问题是替换我们的Web配置中的applicationSettings部分中的值.我们不能让msdeploy替换值,因为我们要替换的内容是xml元素中的文本,而不是属性值(我们得到的警告是:"无法在节点类型'Element'上设置值").
相关配置如下所示:
<applicationSettings>
<Name.Of.Assembly.Properties.Settings>
<setting name="someSetting" serializeAs="String">
<value>I wanna be replaced</value>
</setting>
</Name.Of.Assembly.Properties.Settings>
</applicationSettings>
Run Code Online (Sandbox Code Playgroud)
而declare参数xml如下所示:
<parameter name="XX" defaultValue="default">
<parameterEntry kind="XmlFile"
scope="Web\.config$"
match="/configuration/applicationSettings/Name.Of.Assembly.Properties.Settings/setting[@name='someSetting']/value" />
</parameter>
Run Code Online (Sandbox Code Playgroud)
msdeploy只支持替换属性值还是我做错了什么?
我有两个实体,我在EF 5 Code First中创建了一个相当标准的多对多关系.这些是Service和ServiceItem.Service实体包含ServiceItems的集合,ServiceItem包含Services集合.我可以创建,更改和保存数据到任一实体基本属性,没有任何问题.当我尝试将ServiceItem添加到服务或服务到ServiceItem时,它似乎工作,但没有保存任何内容.我已经验证了所有正确的数据库表都已创建,包括带有交叉键的ServiceItemService表.添加项目时,数据库ServiceItemService表未获取任何条目.没有错误,其他一切似乎都很完美.
我有点难过,可以使用一些帮助.以下是课程.
服务类;
public class Service
{
//Default constructor
public Service()
{
//Defaults
IsActive = true;
ServicePeriod = ServicePeriodType.Monthly;
ServicePeriodDays = 0;
ServiceItems = new Collection<ServiceItem>();
}
public int ServiceID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public ICollection<ServiceItem> ServiceItems { get; set; }
public string TermsOfService { get; set; }
public ServicePeriodType ServicePeriod { get; set; }
public int ServicePeriodDays { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 我像这样使用剃须刀引擎:
public class EmailService : IService
{
private readonly ITemplateService templateService;
public EmailService(ITemplateService templateService)
{
if (templateService == null)
{
throw new ArgumentNullException("templateService");
}
this.templateService = templateService;
}
public string GetEmailTemplate(string templateName)
{
if (templateName == null)
{
throw new ArgumentNullException("templateName");
}
Assembly assembly = Assembly.GetAssembly(typeof(EmailTemplate));
Stream stream = assembly.GetManifestResourceStream(typeof(EmailTemplate), "{0}.cshtml".FormatWith(templateName));
string template = stream.ReadFully();
return template;
}
public string GetEmailBody(string templateName, object model = null)
{
if (templateName == null)
{
throw new ArgumentNullException("templateName");
}
string template = GetEmailTemplate(templateName); …Run Code Online (Sandbox Code Playgroud) 我有以下代码
<div class="editor-label">
@Html.LabelFor(model => model.subCategoryName)
</div>
Run Code Online (Sandbox Code Playgroud)
它将html呈现为
<div class="editor-label">
<label for="subCategoryName">Sub-Category Name</label>
</div>
Run Code Online (Sandbox Code Playgroud)
如何在没有<label>但仍从ViewModel DataAnnotations获取值的情况下呈现干净的HTML,如:
[Display(Name = "Sub-Category Name")]
public string subCategoryName { get; set; }
<div class="editor-label">
Sub-Category Name
</div
Run Code Online (Sandbox Code Playgroud)
我已经尝试了@ Html.XXXXXX(.DisplayTextFor,.DisplayNameFor等等)的所有方法 - 并且仍然无法使其工作.
如何获取登录用户的UserId?我正在使用标准系统生成的AccountModel.我可以使用以下命令获取用户名
User.Identity.Name
Run Code Online (Sandbox Code Playgroud)
但我没有看到UserId字段.我想将UserId用作另一个表的外键.
我使用Unity成功为所有常规构造注射,如仓库等,但我不能让它与ASP.NET身份类的工作.设置是这样的:
public class AccountController : ApiController
{
private UserManager<ApplicationUser> _userManager { get; set; }
public AccountController(UserManager<ApplicationUser> userManager)
{
if (userManager == null) { throw new ArgumentNullException("userManager"); }
_userManager = userManager;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
使用Unity的这些配置:
unity.RegisterType<AccountController>();
unity.RegisterType<UserManager<ApplicationUser>>(new HierarchicalLifetimeManager());
unity.RegisterType<IUserStore<ApplicationUser>, UserStore<ApplicationUser>>(new HierarchicalLifetimeManager());
Run Code Online (Sandbox Code Playgroud)
这与Autofac,Ninject的其他帖子相同,例如,但在我的情况下它不起作用.错误消息是:
尝试创建"AccountController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.手动创作当然是:
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>("Mongo")))
{
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
UPDATE
正如@emodendroket所建议的,缩短代码就可以了.不需要Unity.Mvc包.
unity.RegisterType<IUserStore<IdentityUser>,
MyCustomUserStore>(new HierarchicalLifetimeManager());
Run Code Online (Sandbox Code Playgroud)
和
public AccountController(UserManager<IdentityUser> _userManager,
IAccountRepository _account)
{
// ...
Run Code Online (Sandbox Code Playgroud) c# asp.net dependency-injection unity-container asp.net-identity
在他的Coursera课程的倒数第二次讲座中,奥德斯基教授提供了以下for理解作为可爱案例研究的最后一步:
def solutions(target: Int): Stream[Path] =
for {
pathSet <- pathSets
path <- pathSet
if path.endState contains target
} yield path
Run Code Online (Sandbox Code Playgroud)
在之前的一次演讲中,他在for理解和SQL 之间进行了一些类比.
我正在寻找的yield只是那些path拥有一个DISTINCT endState.
有没有办法从相同理解的过滤条款中回溯到已经产生的项目?
另一种方法可能是转换pathSets到Map从endState到path了之前for的语句,然后将其转换回一个Stream返回之前.但是,这似乎失去了使用a的懒惰计算好处Stream.
同一个案例研究的早期方法实现了类似的目标,但它已经是一个递归函数,而这个函数(似乎)不需要递归.
看起来我可以使用mutable Set来跟踪endState得到的s,但是感觉不满意,因为到目前为止该课程已成功避免使用可变性.
我试图找到一种在Angular2中动态构建模板的方法.我在想templateRef可能会提供一种方法来做到这一点.但我可能是错的.
我在这个例子中看着templateRef.我注意到语法是[ng-for-template]我也尝试过[ngForTemplate]因为我知道最近发生了变化.
所以此刻我有这个:
import {Component, TemplateRef} from 'angular2/core';
@Component({
selector : 'body',
template : `
<template [ngForTemplate]="container">
<div class="container"></div>
</template>
`
})
export class App
{
@ContentChild(TemplateRef) container;
constructor() {}
ngAfterContentInit()
{
console.log(this);
}
}
Run Code Online (Sandbox Code Playgroud)
此示例引发错误:
import {Component, TemplateRef} from 'angular2/core';
@Component({
selector : 'body',
template : `
<template [ngForTemplate]="container">
<div class="container"></div>
</template>
`
})
export class App
{
@ContentChild(TemplateRef) container;
constructor() {}
ngAfterContentInit()
{
console.log(this);
}
}
Run Code Online (Sandbox Code Playgroud)
所以首先我想知道.这样做的正确方法是什么?文档没有提供任何示例.
其次,有没有一种方法可以将新的模板逻辑添加到我的模板或动态构建模板?应用的结构可以是非常大量的不同结构组合.所以,如果可能的话,我想看看是否有一种方法可以做到这一点,而不需要一个包含大量不同ngIf和ngSwitch语句的庞大模板.
我的问题实际上是关于templateRef的第一部分.但是对第二部分的任何帮助或建议表示赞赏.
我有这样的普通绑定{{foo}},它在HTML中显示foo的值作为文本.来自服务器的文本是"R&D".我需要这个显示为"R&D".有帮助吗?
我有一个异步函数,由我的代码中的某个地方的setInterval运行.此函数定期更新某些缓存.
我还有一个不同的同步函数需要检索值 - 最好是从缓存中检索,如果它是缓存未命中,那么从数据源(我意识到以同步方式进行IO操作是不明智的,但我们假设在这种情况下这是必需的).
我的问题是我希望同步函数能够等待来自异步函数的值,但是不可能await在非async函数内使用关键字:
function syncFunc(key) {
if (!(key in cache)) {
await updateCacheForKey([key]);
}
}
async function updateCacheForKey(keys) {
// updates cache for given keys
...
}
Run Code Online (Sandbox Code Playgroud)
现在,通过将内部逻辑提取updateCacheForKey到新的同步函数中,并从现有函数中调用此新函数,可以轻松地避免这种情况.
我的问题是为什么首先绝对防止这个用例?我唯一的猜测是它与"白痴"有关,因为在大多数情况下,从同步函数等待异步函数是错误的.但是我认为它有时会有其有效的用例我错了吗?
(我认为这在C#中也可以使用Task.Wait,虽然我可能会在这里混淆一些事情).
c# ×3
angular ×2
javascript ×2
asp.net ×1
asp.net-mvc ×1
async-await ×1
asynchronous ×1
many-to-many ×1
msdeploy ×1
razor ×1
razorengine ×1
scala ×1
sql ×1
web-config ×1