我知道'this'在Java中起到了参考作用.我们只能在类成员中使用它.
我要问的是...因为它在类的成员中使用,这意味着它必须是实例变量或参数.
并假设,如果它是一个方法的参数,但它是在块中工作.block不包含任何params和all ..你能解释它是什么...它在java中的定义是什么?它是如何使用By JVM的.
我有一个客户端在两个端点上使用以下连接到WCF服务:
<security mode="Message">
<message clientCredentialType="Windows" />
</security>
Run Code Online (Sandbox Code Playgroud)
这适用于我的开发环境(都在本地运行),并且协商正常.当我将它推送到测试环境时,我收到以下消息:
与"SOAP安全协商://主机/ HTTP服务为目标" 的http://主机/服务 "失败.有关详细信息,请参阅内部异常
内在的例外:
System.ComponentModel.Win32Exception:安全支持提供程序接口(SSPI)身份验证失败.服务器可能未在标识为" host/server-name.domain " 的帐户中运行.如果服务器正在服务帐户(例如,网络服务)中运行,请将该帐户的ServicePrincipalName指定为服务器的EndpointAddress中的标识.如果服务器在用户帐户中运行,请将该帐户的UserPrincipalName指定为服务器的EndpointAddress中的标识.
在随机更改属性并且通常搞乱之后,我能够使其工作的唯一方法是更改服务的应用程序池以使用LocalSystem作为标识.这随后导致系统管理员有小猫,而不是我可以继续做的事情.
任何人都可以解释为什么会这样吗?客户端Windows帐户和AppPool的标识都在同一个域中.该服务正在同一域中的服务器上运行.
我有一堆Web项目的解决方案,我希望我的构建服务器自动为每个项目创建包.我能够(几乎)一切正常.构建很好,并且将在每个构建上创建包.但只有当我没有在MSBuild参数中指定PublishProfile时.因此它只会插入默认值而不会预编译我的网站等.(参数是/p:DeployOnBuild=True /p:IsAutoBuild=True /p:VisualStudioVersion=12.0)
但是,我想使用我在Visual Studio中创建的发布配置文件(.pubxml).每个项目都有一个"Test.pubxml".但是当我指定PublishProfile参数时,构建将失败,并显示以下错误消息(参数为/p:DeployOnBuild=True;PublishProfile=Test /p:IsAutoBuild=True /p:VisualStudioVersion=12.0):
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets (411): Can't find the valid AspnetCompilerPath
是的,该文件Microsoft.Web.Publishing.AspNetCompileMerge.targets确实存在于该文件夹中.我可以在我的开发人员计算机上从Visual Studio部署项目就好了.
我使用以下内容:Windows Server 2012 R2 Visual Studio Ultimate 2013 Update 1(安装在构建服务器上)项目适用于.Net 4.5.1
我知道这AsyncLocal很棘手。但是,我什至不能100%肯定会受到谴责。我不明白下面的代码是不是“气密”的。
private readonly AsyncLocal<Stack<int>> _myStack = new AsyncLocal<Stack<int>>();
private void MyMethod()
{
var myStack = _myStack.Value ?? (_myStack.Value = new Stack<int>());
myStack.Push(42);
try
{
// code here, which may recursively call the same function again.
// all single-threaded without any async calls, though
}
finally
{
myStack.Pop(); // this occasionally throws "Stack empty"
}
}
Run Code Online (Sandbox Code Playgroud)
引发异常时,此方法中的调用堆栈仅“深”。
没有对的其他引用_myStack,并且myStack(本地var)没有向下传递或在其他任何地方使用。
我的理解在哪里分解?无论使用哪种方式AsyncLocal,我都会抓住一个Stack<>对象,向其推入一些东西-无论发生什么情况,都只在其中弹出一次finally。
没有其他异常抛出-堆栈根本不深(在这种情况下为1或2,可能是3个级别)。没有非托管代码。
我没有最低限度的复制,而且似乎随机发生。这就是为什么AsyncLocal首先要引入它的原因-以防万一有两个线程介入并破坏了Stack可能的内部状态。
我正在编写一个性能关键的.NET应用程序,它大量使用多线程.
使用Visual Studio性能分析器,使用Exclusive样本的顶级函数是:
WaitHandle.WaitAny() - 14.23%
@JIT_MonReliableEnter@8 - 7.76%
Monitor.Enter - 5.09%
基本上,我的前3个函数正在使用线程原语,并且在某种程度上我不相信.相比之下,我的工作/处理程序非常小,我正在努力提高性能.我相信所涉及的算法非常合理,尽管我经常审查它们.
我的问题是:
WaitAny特别是很穷?我大量使用它来检查特定队列对象是否可读/可写,还同时检查中止标志.有没有更好的方法呢?我正在访问配置文件:
var map = new ConfigurationFileMap(configPath);
var config = ConfigurationManager.OpenMappedMachineConfiguration(map);
config.AppSettings.Settings.Add("SomeSetting", "SomeValue");
Run Code Online (Sandbox Code Playgroud)
它适用于任何.exe.config文件,但不适用于任何web.config.
注意:我没有尝试访问当前应用程序的web.config,我试图在任意路径中修改web.config.
(我试过WebConfigurationManager而不是ConfigurationManager,但它给出了相同的结果)
AppSettings属性访问者抛出异常- 尝试GetSection("appSettings")并将其AppSettingsSection转换为相同的异常.无论哪种方式,这里是:
System.InvalidCastException: Unable to cast object of type 'System.Configuration.DefaultSection' to type 'System.Configuration.AppSettingsSection'.
Run Code Online (Sandbox Code Playgroud)
我显然已经四处搜索,但发现只有人访问'当前网络应用'的web.config或使用XmlDocument/ XDocument.
我的猜测是.exe.config文件会自动获得一些推断的configSections类型信息,这意味着它正确地知道如何处理appSettings.但是我不知道为什么,根据文件名,它不适用于web.config.
啊.对于app.config,我正在使用OpenExeConfiguration:
// works fine for .exe.config
var config = ConfigurationManager.OpenExeConfiguration("some-assembly-here.exe");
config.AppSettings.Settings.Add("SomeSetting", "SomeValue");
config.Save();
Run Code Online (Sandbox Code Playgroud)
在这里我使用的OpenMappedMachineConfiguration似乎是machine.config,但是我看不到打开任意web.config文件的另一种方式 - 任何人?
脚步
结果
输出窗口显示:
Commencing deployment for project 0x10c-cloud
...building deployment package obj\Debug\Package\Archive...
...deployment package created at E:\dev\path-to-my-stuff\project-here\obj\Debug\Package\Archive
...build of project archive completed succesfully
...starting deployment to AWS Elastic Beanstalk environment 'mysite'
...starting incremental deployment to environment 'mysite'
Run Code Online (Sandbox Code Playgroud)
5-10分钟后收到错误弹出:
Error deploying new application: Unhandled error during deployment: Deployment Failed: Deployment to AWS Elastic Beanstalk failed with exception: processing .
Deployment to AWS Elastic Beanstalk environment 'mytest' did not complete successfully …Run Code Online (Sandbox Code Playgroud) asp.net-mvc amazon-web-services visual-studio-2012 amazon-elastic-beanstalk
我正在尝试使用部分使用Windows Auth 的MVC5 webapp .
我的意思是,它实际上是基于表单/ cookie的身份验证,但请求用户的Windows主体构成了他们的登录凭据的一部分.
例如,登录页面会显示"您已被识别为somedomain\kierenj.请输入密码以登录." 如果他们输入了正确的代码,则会设置cookie并登录.
如果Windows身份验证失败,则仍会显示登录页面,但会被禁用.
我已经尝试过像这样的WindowsPrincipalHanlder:https://github.com/JabbR/JabbR/blob/master/JabbR/Middleware/WindowsPrincipalHandler.cs
它的要点是,如果我启用Windows身份验证并禁用匿名身份验证,那么Owin(或者可能是它的cookie auth部分)重定向到登录页面 - 它重定向到登录页面 - 它是一个重定向循环.
注意我使用的是非常简化的Owin设置. UseCookieAuthentication与ApplicationCookie类型和LoginPath指定; 然后我SignIn从我的帐户控制器那样打电话:
var claims = new[] {
new Claim(ClaimTypes.Name, "Username"),
new Claim(ClaimTypes.Role, "AuthenticatedUser")
};
AuthenticationManager.SignIn(new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie));
Run Code Online (Sandbox Code Playgroud)
(首先检查WindowsIdentity.GetCurrent()过)
我真的需要编写自己的Owin cookie auth中间件版本吗?我可以获取源代码以便我可以调试/派生吗?
我正在存储更新操作:
class Update
{
public Expression MemberExpression { get; set; }
public Type FieldType { get; set; }
public object NewValue { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
例如:
var myUpdate = new Update
{
MemberExpression = (MyType o) => o.LastModified,
FieldType = typeof(DateTime?),
NewValue = (DateTime?)DateTime.Now
}
Run Code Online (Sandbox Code Playgroud)
然后我试图稍后应用此更新(简化):
var lambda = myUpdate.MemberExpression as LambdaExpression;
var memberExpr = lambda.Body as MemberExpression;
var prop = memberExpr.Member as PropertyInfo;
prop.SetValue(item, myUpdate.Value);
Run Code Online (Sandbox Code Playgroud)
但是,myUpdate.Value是一个DateTime,而不是一个DateTime?.这是因为当你将一个可空值转换为a时object,它会变为null或包装值类型.
因为它(DateTime?)myUpdate.Value …
我与大合作,和不断增长的使用内存映射文件的托管的包装文件:MemoryMappedFile,MemoryMappedViewAccessor。
我使用以下代码创建空文件:
long length = 1024L * 1024L * 1L; // 1MB
// create blank file of desired size (nice and quick!)
FileStream fs = new FileStream(filename, FileMode.CreateNew);
fs.Seek(length, SeekOrigin.Begin);
fs.WriteByte(0);
fs.Close();
// open MMF and view accessor for whole file
this._mmf = MemoryMappedFile.CreateFromFile(filename, FileMode.Open);
this._view = this._mmf.CreateViewAccessor(0, 0, MemoryMappedFileAccess.ReadWrite);
Run Code Online (Sandbox Code Playgroud)
可以正常工作,最大1GB。当我尝试2GB时,我得到了IOException:
Not enough storage is available to process this command.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.MemoryMappedFiles.MemoryMappedView.CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, Int64 offset, Int64 size) …Run Code Online (Sandbox Code Playgroud)