我一直在探索重新发明DataTable,我想知道它的用途是什么MarshalByValueComponent.我相信它是用于.NET远程处理(也许WinForms和的WebForms),但被换下的WCF取代.我在GitHub或Google上找不到任何值得注意的用法.是否MarshalByValueComponent仍在使用?
试图在核心mvc项目中打开防伪,但没有运气.做了什么:
添加过滤器以自动检查每个POST请求上的防伪标记.
services.AddMvc(o =>
{
o.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
Run Code Online (Sandbox Code Playgroud)
令牌生成以这种方式添加到每个页面.
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Antiforgery;
@{
var antiforgeryRequestToken = Antiforgery.GetAndStoreTokens(Context).RequestToken;
}
...
...
<script>
var antiforgeryToken = @Json.Serialize(antiforgeryRequestToken);
</script>
Run Code Online (Sandbox Code Playgroud)
最后每个客户端ajax请求都添加了RequestVerificationToken这种方式.
var options = {
url: o.url, type: 'POST', data: o.params, headers: { 'RequestVerificationToken': antiforgeryToken } };
Run Code Online (Sandbox Code Playgroud)
我可以看到每个ajax请求都有令牌,但我总是为任何POST请求获得400.如果我禁用过滤器,它可以正常工作.但是一旦我启用它,asp.net核心就会在每个POST请求上启动验证,它总是返回400.
有任何想法吗?
更新:
我按照评论中的说明进行操作,现在代码如下所示.ConfigureServices方法:
services.AddMvc(o => {
o.Filters.Add(new HandleAllExceptionsFilterFactory());
o.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
});
services.AddAntiforgery(o => o.CookieName = "XSRF-TOKEN");
Run Code Online (Sandbox Code Playgroud)
这是注册的中间件:
app.Use(next => context => {
if (context.Request.Path == "/")
{
var antiforgery = app.ApplicationServices.GetService<IAntiforgery>();
var token = …Run Code Online (Sandbox Code Playgroud) 所以我有一个订单列表......如果列表为空,我想跳转到'其他'.
但是因为它的列表(即使它是空的)还有一个实例吗?对?无论如何,如果没有订单它仍然进入if语句,所以我尝试添加.count == 0...
但它仍然进入if语句......如果订单中没有实际记录,我需要说什么呢?其他....感谢任何回复
IEnumerable<OrderRecord> orders = _orderService.GetOrdersByCustomer(id, OrderStatus.Completed).ToArray();
if (orders != null && orders.Count() == 0 )
{
//order exists
}
else
{
//no order
}
Run Code Online (Sandbox Code Playgroud) 我遵循教程Windows Azure SDK for Node.js - Compute Management来管理虚拟机.
我使用azure account cert exportto 下载了pem文件<Subscription GUID>.pem.
该脚本目前包含:
var subscriptionId ="<Subscription GUID>";
var pem = "<Subscription GUID>.pem";
var computeManagementClient = computeManagement.createComputeManagementClient(computeManagement.createCertificateCloudCredentials({
subscriptionId: subscriptionId,
pem: fs.readFileSync(pem)
}));
Run Code Online (Sandbox Code Playgroud)
当我从Node.js运行它时会产生错误:
C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:416
throw new Error('Required argument ' + name + ' for function ' + func + ' is
^
Error: Required argument credentials.pem for function CertificateCloudCredentials is not defined
at throwMissingArgument (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:416:9)
at ArgumentValidator._.extend.string (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:426:7)
at C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\services\credentials\certificateCloudCredentials.js:35:9
at Object.validateArgs (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:478:3) …Run Code Online (Sandbox Code Playgroud) 我将FluentData用作数据库的orm,并尝试创建通用查询方法:
internal static T QueryObject<T>(string sql, object[] param, Func<dynamic, T> mapper)
{
return MyDb.Sql(sql, param).QueryNoAutoMap<T>(mapper).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)
除了我班上的职能:
public class MyDbObject
{
public int Id { get; set; }
}
public static MyDbObject mapper(dynamic row)
{
return new MyDbObject {
Id = row.Id
};
}
public static MyDbObject GetDbObjectFromTable(int id)
{
string sql = @"SELECT Id FROM MyTable WHERE Id=@Id";
dynamic param = new {Id = id};
return Query<MyDbObject>(sql, param, mapper);
}
Run Code Online (Sandbox Code Playgroud)
在Query<MyDbObject>(sql, param, mapper)编译器上说:
An anonymous function or …
我<asp:Label> 希望根据我传递给它的Generic对象进行填充.
目前我有以下代码: -
private void PopulateEnglishQuestion(int questionId)
{
ReportQuestion reportQuestion = questionsBll.GetReportQuestions().Where(x=> x.ReportQuestionId == questionId).FirstOrDefault();
PopulateLabels(reportQuestion);
}
private void PopulateTranslatedQuesiton(int questionId)
{
ReportQuestionTranslation reportQuestionTranslation = questionsBll.GetReportQuestionsTranslation().Where(x => x.QuestionId == questionId).FirstOrDefault();
PopulateLabels(reportQuestionTranslation);
}
private void PopulateLabels<T>(T item)
{
lblQuestionTitle.Text = typeof (T) == typeof (ReportQuestion)
? ((ReportQuestion) (item)).ReportQuestionTitle
: ((ReportQuestionTranslation) (item)).ReportQuestionTitleTrans;
}
Run Code Online (Sandbox Code Playgroud)
如何让PopulateLabels方法正常工作?
我想在C#中使用模块化编程.我试图用Linq查询创建一个方法.据我所知,我需要将Linq查询存储在变量中以便执行它.我创建了一个名为的类和方法SearchStudent(),但我不知道如何返回Linq查询.我该怎么办?
public var SearchStudent(string ogrenci_id)
{
var query =
from d in context.ogrencis
where d.ogrenci_id ==Convert.ToInt32(ogrenci_id)
select new
{
d.ogrenci_adi,
d.ogrenci_soyadi
};
return query;
}
Run Code Online (Sandbox Code Playgroud) 我正在IProducerConsumerCollection(T)从一个接口中公开一个接口,该接口将定期为另一个线程添加项目以供使用.
public interface IProducer<T>
{
IProducerConsumerCollection<T> ProducerCollection { get; }
}
Run Code Online (Sandbox Code Playgroud)
我试图BlockingCollection(T)在现有集合中使用a ,但似乎IProducerConsumerCollection(T)不支持直接添加:
var queue = new ConcurrentQueue<string>();
var blockingCollection = new BlockingCollection<string>(queue);
var task1 = Task.Run(() => {
Console.WriteLine("Dequeued " + blockingCollection.Take());
Console.WriteLine("Dequeued " + blockingCollection.Take());
});
var task2 = Task.Run(() => {
Console.WriteLine("Enqueueing Hello");
queue.Enqueue("Hello");
Console.WriteLine("Enqueueing World");
queue.Enqueue("World");
});
Task.WaitAll(task1, task2);
Run Code Online (Sandbox Code Playgroud)
这将无限期挂起,因为它BlockingCollection(T)不会注意到新项目.
是否有类似于该BlockingCollection(T).Take方法的功能,或者有什么比这更简单:
static async Task<T> TakeAsync<T>(
IProducerConsumerCollection<T> collection,
CancellationToken token
)
{
T result;
while(!collection.TryTake(out result))
{ …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×2
asp.net-mvc ×2
.net ×1
.net-4.0 ×1
asp.net-core ×1
azure ×1
delegates ×1
fluentdata ×1
function ×1
generic-list ×1
generics ×1
node.js ×1
orm ×1
return ×1
var ×1