我有一个自定义编辑器模板,我在其中添加值,ViewData所以:
@Html.EditorFor( model => model.PhoneNumber , new { Title = "SomeValue" } )
Run Code Online (Sandbox Code Playgroud)
如何访问值和属性名称?
我有由N个线程并发处理的表.
CREATE TABLE [dbo].[Jobs]
(
[Id] BIGINT NOT NULL CONSTRAINT [PK_Jobs] PRIMARY KEY IDENTITY,
[Data] VARBINARY(MAX) NOT NULL,
[CreationTimestamp] DATETIME2(7) NOT NULL,
[Type] INT NOT NULL,
[ModificationTimestamp] DATETIME2(7) NOT NULL,
[State] INT NOT NULL,
[RowVersion] ROWVERSION NOT NULL,
[Activity] INT NULL,
[Parent_Id] BIGINT NULL
)
GO
CREATE NONCLUSTERED INDEX [IX_Jobs_Type_State_RowVersion] ON [dbo].[Jobs]([Type], [State], [RowVersion] ASC) WHERE ([State] <> 100)
GO
CREATE NONCLUSTERED INDEX [IX_Jobs_Parent_Id_State] ON [dbo].[Jobs]([Parent_Id], [State] ASC)
GO
Run Code Online (Sandbox Code Playgroud)
作业正在添加到表中State=0 (New)- 它可以被此状态下的任何工作者使用.当worker获取此队列项时,State更改为,50 (Processing)并且其他使用者无法使用该作业(工作程序[dbo].[Jobs_GetFirstByType] …
我尝试使用以下设置测试NLog性能(最新版本):
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<variable name="basePath" value="c:\logs\" />
<variable name="msgFormat" value="${message}" />
<targets async="true">
<target name="file"
xsi:type="File"
fileName="${basePath}/${logger}/${date:format=yyyy}/${date:format=MMMM}/log-${date:format=yyMMdd}-${level}.log"
layout="${msgFormat}"
concurrentWrites="true" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file"/>
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
并运行此代码:
var msg = "this is example string for logging test. it's not very long, but not very short";
var count = 20000;
Parallel.For(0, count, x => nlog.Info(msg));
Run Code Online (Sandbox Code Playgroud)
NLog写入文件,但当文件大小达到1MB时,它将停止写入.我尝试使用简单的for循环,但它没有帮助我.我尝试使用内部日志记录,但没有错误,顺便说一下,我看到这个字符串:
2013-04-01 11:36:18.2458跟踪打开c:\ logs/NLogTest/2013/April/log-130401-Info.log with concurrentWrite = False
这很奇怪,因为concurrentWrites默认值是true,而且我在config中设置了这个值.
我如何输入有关错误的详细信息?我试图设置customErrors mode到On/Off,而我有的只是:Sorry, an error occurred while processing your request.
我如何将此代码转换为剃刀语法:
<% for (int i = 0; i < items.Length; i++) %>
<%{
if (i % 3 == 0)
{ %>
<tr>
<% } %>
<td><a href="<%: url[i] %>"><%: title[i] %></a></td>
<% if (i % 3 == 2)
{ %>
</tr>
<% } %>
<%} %>
Run Code Online (Sandbox Code Playgroud)
我试试,但没有成功:
@for (int i = 0; i < items.Length; i++)
{
if (i % 3 == 0)
{
<tr>
}
<td><a href="@(url[i])">@(title[i])</a></td>
if (i % 3 == 2)
{
</tr>
}
}
Run Code Online (Sandbox Code Playgroud) 我存储在HttpContext.Current.Session当前用户中,SiteUser是单音类,它呈现当前活动的siteuser,当他记录我在控制器中创建新的SiteUser()并在构造函数中将他添加到会话中:
public static SiteUser Create()
{
HttpContext.Current.Session[sessionKey] = new SiteUser();
return HttpContext.Current.Session[sessionKey] as SiteUser;
}
Run Code Online (Sandbox Code Playgroud)
然后,对于服务器服务的每个请求,我检查用户是否在会话中可用:
public static SiteUser Current
{
get
{
if (HttpContext.Current.Session == null || HttpContext.Current.Session[sessionKey] == null)
{
throw new SiteUserAutorizationExeption();
}
return HttpContext.Current.Session[sessionKey] as SiteUser;
}
}
Run Code Online (Sandbox Code Playgroud)
否则我将生成非auth用户异常并将其重定向到登录页面.但有时HttpContext.Current.Session [sessionKey]为null,但HttpContext.Current.Session不为null且FormsAuthenticationTicket可用且Expired属性也为false.有人可以帮助我,为什么HttpContext.Current.Session [sessionKey]可以为空?
UPD:webconfig会话设置:<sessionState mode="InProc" timeout="20" />
UPD:sessionKey是:public const string sessionKey = "SiteUser";
UPD2:我忘了添加,在会话中还存储了文化设置:
HttpContext.Current.Session["Culture"]
Run Code Online (Sandbox Code Playgroud)
当异常命中时,HttpContext.Current.Session [sessionKey]为null,culture-item不是
UPD3:我已下载源.NET Framework的符号表,并在更改集合项时在SessionStateItemCollection上设置断点.我解决了一些错误:1)所有的收集项都是空的 - "文化"正在设置2)它发生在会话结束事件我无法理解它是怎么回事,因为在web.config会话超时设置为20
我尝试使用Html.EditorFor()帮助程序将数据绑定到模型并提交,但模型来到控制器是空的.
这是模型代码:
public class LogOnModel
{
[LocalizedRequired]
[LocalizedDisplayName("User Name")]
public string UserName { get; set; }
[LocalizedRequired]
[DataType(DataType.Password)]
[LocalizedDisplayName("Password")]
public string Password { get; set; }
[LocalizedDisplayName("Remember Me")]
public bool RememberMe { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是cshtml:
@model Models.LogOnModel
{
View.Title = "Log On";
}
@using (Html.BeginForm())
{
@Html.EditorFor(m => m.UserName);
@Html.EditorFor(m => m.Password);
<input type="submit" value="LogOn" />
}
Run Code Online (Sandbox Code Playgroud)
和HTML代码生成如下:
<input id="UserName_UserName" name="UserName.UserName" type="text" value="qwerty" />
<input id="Password_Password" name="Password.Password" type="password" />
Run Code Online (Sandbox Code Playgroud)
它似乎是html生成的代码中的错误,它应该是id ="someid"value ="somevalue",但不是id ="someid_someid"value ="somevalue.somevalue"
.net ×4
c# ×3
razor ×3
asp.net ×1
concurrency ×1
locking ×1
logging ×1
nlog ×1
sql-server ×1
t-sql ×1