如何%APPDATA%使用app.config文件登录特殊文件夹(例如)?
我可以通过编程方式完成,但我需要能够使用app.config文件进行配置.我看过一篇关于使用的文章.%envFolderPath它在最新发布的版本中没有,但仅限于最新的代码.
下面是我以编程方式将日志设置为特殊文件夹的代码.
public void ExampleLog
{
XmlConfigurator.Configure();
var fileName = GetFileName();
var appender = new log4net.Appender.RollingFileAppender
{
Layout = new log4net.Layout.PatternLayout("%d - %m%n"),
File = fileName,
MaxSizeRollBackups = 10,
MaximumFileSize = "100MB",
AppendToFile = true,
Threshold = Level.Debug
};
appender.ActivateOptions();
BasicConfigurator.Configure(appender);
}
private static string GetFileName()
{
const string subPath = "MySubFolder";
var path = String.Format(@"{0}\{1}", Environment.GetFolderPath (Environment.SpecialFolder.CommonApplicationData), subPath);
const string logName = "Log.txt";
return Path.Combine(path, logName);
}
Run Code Online (Sandbox Code Playgroud) 我收到以下错误: -
System.InvalidOperationException:XmlReader状态应为Interactive.System.Xml.Linq.XDocument.Load(XmlReader reader,LoadOptions选项)中的System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r,LoadOptions o)
在以下代码中.有谁能指出我在这里做错了什么?
static XDocument GetContentAsXDocument(string xmlData)
{
XmlDocument xmlDocument = new XmlDocument();
if (!string.IsNullOrEmpty(xmlData))
{
xmlDocument.LoadXml(xmlData);
return xmlDocument.ToXDocument();
}
else
{
return new XDocument();
}
}
/// <summary>
/// Converts XMLDocument to XDocument
/// </summary>
/// <param name="xmlDocument"></param>
/// <returns></returns>
public static XDocument ToXDocument( this XmlDocument xmlDocument )
{
using( var nodeReader = new XmlNodeReader( xmlDocument ) )
{
nodeReader.MoveToContent();
return XDocument.Load(
nodeReader,
(LoadOptions.PreserveWhitespace |
LoadOptions.SetBaseUri |
LoadOptions.SetLineInfo));
}
}
Run Code Online (Sandbox Code Playgroud) 在其中一个动作中,我做了类似的事情
public HttpResponseMessage Post([FromBody] Foo foo)
{
.....
.....
var response =
Request.CreateResponse(HttpStatusCode.Accepted, new { Token = "SOME_STRING_TOKEN"});
return response;
}
Run Code Online (Sandbox Code Playgroud)
以及更多像这样返回匿名类型实例的方法,它运行良好.
现在,我正在为它编写测试.我有
HttpResponseMessage response = _myController.Post(dummyFoo);
Run Code Online (Sandbox Code Playgroud)
HttpResponseMessage有一个叫做的房产Content,有一个ReadAsAsync<T>().
我知道如果有具体的具体类型,我可以做到
Bar bar = response.Content.ReadAsAsync<Bar>();
Run Code Online (Sandbox Code Playgroud)
但是如何访问正在返回的匿名类型?可能吗?
我希望做到以下几点:
dynamic responseContent = response.Content.ReadAsAsync<object>();
string returnedToken = responseContent.Token;
Run Code Online (Sandbox Code Playgroud)
但我收到错误,类型对象的实例没有属性令牌.即使调试器显示带有一个属性Token的responseContent,也会发生这种情况.我理解为什么会这样,但我想知道是否有办法访问该属性.

谢谢
我正在使用此代码生成 U+10FFFC
var s = Encoding.UTF8.GetString(new byte[] {0xF4,0x8F,0xBF,0xBC});
Run Code Online (Sandbox Code Playgroud)
我知道它是供私人使用的,但它确实显示了一个单一字符,就像我在展示它时所期望的那样.操作此unicode字符时出现问题.
如果我以后这样做:
foreach(var ch in s)
{
Console.WriteLine(ch);
}
Run Code Online (Sandbox Code Playgroud)
它不打印单个字符,而是打印两个字符(即字符串显然由两个字符组成).如果我改变我的循环,将这些字符添加回空字符串,如下所示:
string tmp="";
foreach(var ch in s)
{
Console.WriteLine(ch);
tmp += ch;
}
Run Code Online (Sandbox Code Playgroud)
在这结束时,tmp将只打印一个字符.
到底发生了什么?我认为它char包含一个unicode字符,除非我正在转换为字节,否则我永远不必担心字符有多少字节.我真正的用例是我需要能够检测字符串中何时使用非常大的unicode字符.目前我有这样的事情:
foreach(var ch in s)
{
if(ch>=0x100000 && ch<=0x10FFFF)
{
Console.WriteLine("special character!");
}
}
Run Code Online (Sandbox Code Playgroud)
但是,由于这种非常大的字符分裂,这不起作用.如何修改它以使其工作?
我正在创建一个html表.我想要隐藏表格行.我将属性runat=server和id特定行放在一起,但该行中有客户端代码,类似于以下代码.
<% if ((strFlag=="d") || (strApprvdFlag=="y")) {%>
Run Code Online (Sandbox Code Playgroud)
调用此行后,我收到此错误.
在asp.net控件中,此上下文不支持代码块.
以下是我的示例代码:
<table>
<tr colspan="4" ID="trMedical" scriptrunat="server">
<td style="WIDTH: 45px;HEIGHT: 12px" align="left" class="LabelTaxText" width="45"><b>G
</b>
</td>
<td style="WIDTH: 182px;HEIGHT: 12px" class="LabelTaxText" align="left" width="182"
colSpan="2">Medical
</td>
<td style="WIDTH: 81px; HEIGHT: 12px" align="right" class="LabelTaxText" width="81">
<asp:textbox onchange="onChangeFlag(),intOnly(this);" onkeyup="intOnly(this);" onkeypress="return CheckNumericWithOutDecimals(event)"
id="TxtMedical" tabIndex="24" runat="server" Width="96px" MaxLength="12" style="Z-INDEX: 0"></asp:textbox>
</td>
<% if ((strFlag=="d") || (strApprvdFlag=="y")) {%>
<td class="LabelTaxText" style="WIDTH: 107px; HEIGHT: 12px" align="right" width="107">
<asp:textbox onchange="onChangeFlag(),intOnly(this);" onkeyup="intOnly(this);" onkeypress="return CheckNumericWithOutDecimals(event)" id="TxtMedicalProof" tabIndex="24" onblur="charAlert(TxtMedical,TxtMedicalProof)" …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试以下内容:
protected IHealthStatus VerifyMessage(ISubscriber destination)
{
var status = new HeartBeatStatus();
var task = new Task<CheckResult>(() =>
{
Console.WriteLine("VerifyMessage(Start): {0} - {1}", DateTime.Now, WarningTimeout);
Thread.Sleep(WarningTimeout - 500);
Console.WriteLine("VerifyMessage(Success): {0}", DateTime.Now);
if (CheckMessages(destination))
{
return CheckResult.Success;
}
Console.WriteLine("VerifyMessage(Pre-Warning): {0} - {1}", DateTime.Now, ErrorTimeout);
Thread.Sleep(ErrorTimeout - 500);
Console.WriteLine("VerifyMessage(Warning): {0}", DateTime.Now);
if (CheckMessages(destination))
{
return CheckResult.Warning;
}
return CheckResult.Error;
});
task.Start();
task.Wait();
status.Status = task.Result;
return status;
}
Run Code Online (Sandbox Code Playgroud)
通过以下单元测试:
public void HeartBeat_Should_ReturnWarning_When_MockReturnsWarning()
{
// Arrange
var heartbeat = new SocketToSocketHeartbeat(_sourceSubscriber.Object, _destinationSubscriber.Object);
heartbeat.SetTaskConfiguration(this.ConfigurationHB1ToHB2_ValidConfiguration());
// …Run Code Online (Sandbox Code Playgroud) 我不应该使用DbEntityEntry的复杂属性方法或属性方法来获取EntityKey对象.我找不到MSDN的任何示例,但我认为这在Entity Framework 5中是可能的.我不知道实体密钥或实体的名称,因为我使用的是通用存储库接口.
我们有超过3名开发人员在处理单个解决方案文件.因此,我们无法在网站集管理员菜单中添加它们.
当我在Visual Studio中使用管理员凭据进行部署时,我能够成功部署到特定的SharePoint应用程序.当我与这些用户中的任何一个用户登录时,我无法做到.它给了我以下错误:
Error occurred in deployment step 'Recycle IIS Application Pool':
<nativehr>0x80070005</nativehr><nativestack></nativestack>Access denied
Run Code Online (Sandbox Code Playgroud)
我们已授予这些用户登录Active Directory的管理权限.
我们可以做些什么来解决这个问题?
c# ×6
asp.net ×2
unit-testing ×2
.net ×1
app-config ×1
ashx ×1
char ×1
code-behind ×1
dataset ×1
linq-to-xml ×1
log4net ×1
moq ×1
mstest ×1
resources ×1
sharepoint ×1
unicode ×1
utf-16 ×1
xml ×1
xmldocument ×1