我被卡住了. 说真的...... - 解决了.请继续阅读:)
场景:我想在这里做正确的事情.我依靠Thinktecture Identitymodel CORS DelegatingHandler将CORS功能添加到我的REST服务(ASP.NET Web-API).到现在为止还挺好.
为了实际测试它是否正常工作,我做了以下事情:
所以我出去看了Fiddler跟踪和IIS日志.Fiddler说没有GET/rest/hello请求,而是一个OPTIONS/rest/hello请求 - 这完全没问题且预期!但是对OPTIONS请求的响应相当有趣!
整个响应头看起来像这样:
HTTP/1.1 200 OK
Allow: OPTIONS, TRACE, GET, HEAD, POST
Server: Microsoft-IIS/7.5
Public: OPTIONS, TRACE, GET, HEAD, POST
Date: Fri, 15 Feb 2013 14:09:27 GMT
Content-Length: 0
Run Code Online (Sandbox Code Playgroud)
这当然远不及预期的反应.有趣的是,请求甚至没有在我的应用程序中命中Application_BeginRequest().所以我的应用程序无法对该结果负责.我可以在我的IIS日志中看到请求,IIS添加了Powered-by-ASP.NET标头..因此它肯定会通过(右侧)IIS站点.
触发ajax请求的JQuery代码:
function Run()
{
$.ajax({
type: 'GET',
url: url,
dataType: "json",
beforeSend: function(jqXhr) {
jqXhr.setRequestHeader("Authorization", "Basic " + getBasicHttpEncodedString(userName, password));
jqXhr.setRequestHeader("Api-Key", "123");
},
success: successCallback, …Run Code Online (Sandbox Code Playgroud) 我需要在我的动作过滤器中访问当前登录的用户.身份由DelegatingHandler进一步的执行链设置.
我可以访问当前IPrincipal使用HttpContext.Current.User.
到目前为止,我避免使用HttpContext.Current,因为在我看来是坏风格.首先,你的代码只有在IIS中托管时才能工作,其次它包含一个System.Web我认为不会受到伤害的引用,但System.Net.Http如果可能的话,我更愿意坚持使用.
依靠好的旧" HttpContext" 感觉不对.
有没有其他方法可以访问用户的身份ActionFilter?或者,HttpContext如果您不打算运行自托管应用程序,是否可以使用?
authentication iprincipal actionfilterattribute asp.net-web-api
在VS 2013中,从构建过程中运行powershell脚本变得非常简单.不幸的是,没有写入主机命令被记录到tfs构建日志中.
因此,在构建完成后,我无法查看日志文件并查看powershell shell脚本实际执行的操作.
日志文件只说:
Run optional script after MSBuild 00:03
Run optional script before Test Runner 00:00
Run VS Test Runner 00:00
Run optional script after Test Runner 00:00
...
Run Code Online (Sandbox Code Playgroud)
ActivityLog.AgentScope.1.xml日志文件更健谈,但信息太少.
Run optional script after MSBuild00:00:03
InputsEnvironmentVariables:
Enabled: True
Arguments:
FilePath: $/CMP04/Some/Project/Main/Web/.scripts/CI/CI.ps1
OutputsResult: 0
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -NoProfile -NonInteractive -File "D:\ws_build\1\CMP04\IP-Main\src\Some\Project\Main\Web\.scripts\CI\CI.ps1"
Run Code Online (Sandbox Code Playgroud)
知道如何将任何调试信息输入到tfs构建日志中吗? 我当然可以创建一个额外的日志文件,但那是计划b :)
编辑:写入主机正在记录到代理的日志xml.write-verbose不是.
我理解等待完成任务(等待).但我对这实际意味着什么感到困惑.
该代码不工作:
public async override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Response.Content != null)
{
var responseContent = await actionExecutedContext.Response.Content.ReadAsStringAsync();
DoSomething(responseContent);
}
}
Run Code Online (Sandbox Code Playgroud)
该代码做的工作:
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Response.Content != null)
{
var responseContent = actionExecutedContext.Response.Content.ReadAsStringAsync().ContinueWith(
task =>
{
DoSomething(task.Result);
});
}
}
Run Code Online (Sandbox Code Playgroud)
显然错误消息异步模块或处理程序在异步操作仍处于挂起状态时完成.告诉我,没有等待异步调用完成,而是"主"线程继续.我期望线程继续但不在当前方法中.我认为线程将返回到asp.net堆栈执行其他工作并在await asyncOperation()操作完成后返回.
我也在其他地方使用等待 - (例如等待Web服务响应) - 我没有在任何地方遇到过类似的问题.我想知道为什么IActionFilterAttribute的行为不同.实际上,我的Web服务调用可能比将响应内容读入字符串要长.
有人可以赐教吗?我感觉我不理解这个概念.
据我所知,CORS无法确切地保护您,因为您可以确定调用者是谁.因为调用者可以发送他想要的任何ORIGIN标题.实际上我读到的地方你不能通过javascript设置原始标题,因为它是一个受限制的标题 - 但我不太确定.无论如何..如果你要实现自己的HttpClient,你可以轻松伪造你的原始标题,因此消耗你不应该消耗的服务.
其次,如果没有指定Origin头,则请求也可以.例如,我使用谷歌Chrome的Postman扩展,它不发送任何原始标题.实际上,如果您尝试手动添加一个,则不会通过网络发送.
因此...
我知道在关闭'html'标签后你不应该放任何东西.告诉SharePoint它...
[...]
</body>
</html><!-- Rendered using cache profile:Public Internet (Purely Anonymous) at: 2013-06-06T12:57:10 -->
Run Code Online (Sandbox Code Playgroud)
这就是SharePoint输出缓存调试信息的样子.我希望这个隐藏的评论在每个页面上都可见.切换到源视图并转到文件末尾会让我感到厌倦.
为了不重新发明轮子,我认为将一段javascript代码添加到我的母版页是最明智的选择,该代码将评论复制到我选择的位置(页面内).
关于如何通过javascript获取评论的任何想法?jquery还可以.
如果我想用NLog实现最佳性能,我在代码中应该做些什么来实现这个目标?
(当然我在NLog.config中启用了异步.)
使用委托写日志消息怎么样?
_logger.Info(() => { return "test" });
Run Code Online (Sandbox Code Playgroud)
不幸的是我无法弄清楚如何"正确"使用它.这甚至记录了吗?
_logger.Info(() => { return string.Format("msg", myParams); }); // Is that the way to go?
Run Code Online (Sandbox Code Playgroud) 我的type: section街区看起来很标准。
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "A message *with some bold text* and _some italicized text_."
}
}
Run Code Online (Sandbox Code Playgroud)
我意识到 Slack 的换行长度超过 ~85 个字符(我没有费心去弄清楚确切的数字)。然而,对于我将自己写入 Slack 的任何消息(不是通过 WebApi,不确定它是否在内部被视为块),情况并非如此。
我的问题是:我可以阻止 Slack尽早换行吗?如果有很长的文本对话行并且突然有一条裁剪过的机器人消息散布在多行上,这看起来很难看 - 特别是在大屏幕上。
在我的代码中,我失败了
if (!File.Exists(_configurationFileName)) {...}
Run Code Online (Sandbox Code Playgroud)
在即时窗口中,我打了一个电话Directory.GetCurrentDirectory(),它指向我的" 工作 "文件夹,而不是我期望的" 代码 "文件夹.
Directory.GetCurrentDirectory()
"C:\\SfDevCluster\\Data\\_App\\_Node_0\\My.Application.Type_App2\\work"
Run Code Online (Sandbox Code Playgroud)
所以当然没有找到位于可执行文件旁边的配置文件.
现在我想知道解决方案是什么.
由于我还想继续运行控制台应用程序,我不想实现任何"if service fabric hosting,然后更改当前目录,..."解决方法.
有什么建议?我的.exe.config文件怎么样(如果有的话,怎么会找到它们)?
Service Fabric将当前目录设置为"工作"的原因是什么?这是某种安全机制吗?
代码清理后(profile:StyleCop)它总是为构造函数,属性等创建区域......
#region Constructors and Destructors
public IpDiagnosticsService()
{
// : base()
// NOP. Required for serializer.
}
public IpDiagnosticsService(string applicationName, SPFarm farm) : base(applicationName, farm)
{
// NOP
}
#endregion
#region Properties
// ...omitted.
#endregion
Run Code Online (Sandbox Code Playgroud)
真棒.我不希望这样. 怎么把它关掉?找不到任何选项.
resharper code-formatting stylecop visual-studio resharper-8.0
cors ×2
javascript ×2
jquery ×2
api ×1
async-await ×1
c# ×1
dom ×1
html ×1
http ×1
iprincipal ×1
logging ×1
nlog ×1
powershell ×1
resharper ×1
rest ×1
slack ×1
slack-api ×1
stylecop ×1
tfs ×1
tfs2013 ×1
tfsbuild ×1
web-services ×1