任何人都可以建议如何将时间跨度或int转换为ISO8601持续时间字符串,如http://en.wikipedia.org/wiki/ISO_8601#Durations中所述?
"1小时30分钟"将导致"PT1H30M",例如:
int duration = 90;
string isoString = duration.ToIsoDuration();
Run Code Online (Sandbox Code Playgroud) 有人可以解释一下为什么这段代码:
var marketValueData = new[] {
new { A = "" },
new { A = "" },
new { B = "" },
};
Run Code Online (Sandbox Code Playgroud)
给我错误:
找不到隐式类型数组的最佳类型
虽然这个工作完全正常:
var marketValueData = new[] {
new { A = "" },
new { A = "" },
new { A = "" },
};
Run Code Online (Sandbox Code Playgroud)
除了不同的属性(B在第一个例子的最后一个条目中),它们是相同的.然而第一个没有编译.为什么?
几天前,Chrome开始将我在Wampserver中的所有vHost重定向到https.一切都工作正常,直到几天前,然后有一天我登录在我的网站上工作,Chrome说无法访问该网站,即使我过去使用过相同的URL.Wamp正在运行以及Apache和MySQL,并且这些服务都没有在错误日志中出现任何错误.
我已经尝试删除域(我使用我的本地站点的假.dev扩展名),chrome://net-internals/#hsts但没有做任何事情.我还尝试安装SSL以查看Chrome是否会将其检测为安全连接......没有.我甚至尝试完全重新安装Wamp(即使vHosts在其他浏览器中工作正常)并且没有任何改变.
在Chrome中唯一有效的方法是通过访问网站http://localhost/site.我的所有Apache vHost都会重定向到HTTPS.我用Google搜索并用Google搜索,找不到任何可以解决问题的方法.
我的MVC5项目解决方案中有一个WebAPI控制器.WebAPI有一个方法,它将特定文件夹中的所有文件作为Json列表返回:
[{"name":"file1.zip", "path":"c:\\"}, {...}]
从我的HomeController我想调用此方法,将Json响应转换为List<QDocument>并将此列表返回到Razor视图.此列表可能为空:[]如果文件夹中没有文件.
这是APIController:
public class DocumentsController : ApiController
{
#region Methods
/// <summary>
/// Get all files in the repository as Json.
/// </summary>
/// <returns>Json representation of QDocumentRecord.</returns>
public HttpResponseMessage GetAllRecords()
{
// All code to find the files are here and is working perfectly...
return new HttpResponseMessage()
{
Content = new StringContent(JsonConvert.SerializeObject(listOfFiles), Encoding.UTF8, "application/json")
};
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的HomeController:
public class HomeController : Controller
{
public Index()
{
// I want to …Run Code Online (Sandbox Code Playgroud) 这似乎是一个愚蠢的问题,所以这里是:
除了解析驱动器号的FileInfo.FullPath字符串之外,然后使用DriveInfo("c")等来查看是否有足够的空间来写入此文件.有没有办法从FileInfo获取驱动器号?
我有一个方法,将FileStream作为输入.此方法在for循环内运行.
private void UploadFile(FileStream fileStream)
{
var stream = GetFileStream();
// do things with stream
}
Run Code Online (Sandbox Code Playgroud)
我有另一种方法,它创建并返回FileStream:
private FileStream GetFileStream()
{
using(FileStream fileStream = File.Open(myFile, FileMode.Open))
{
//Do something
return fileStream;
}
}
Run Code Online (Sandbox Code Playgroud)
现在第一个方法抛出一个ObjectDisposedException当我尝试访问返回的FileStream时,可能是因为它已经关闭,因为我正在使用" using"来正确处理流.
如果我不使用"using"而是按如下方式使用它,那么FileStream将保持打开状态,循环的下一次迭代(在同一文件上运行)会抛出异常,告知文件已在使用中:
private FileStream GetFileStream()
{
FileStream fileStream = File.Open(myFile, FileMode.Open);
//Do something
return fileStream;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用try-finally块,我在那里关闭流,finally那么它也会抛出ObjectDisposedException.
如何有效地返回文件流并关闭它?
出于安全原因,我想通过应用程序级别禁用这些方法,所以我有这个web.config文件
<configuration>
<location path="index.php">
<system.webServer>
<directoryBrowse enabled="false" />
</system.webServer>
<system.web>
<authorization>
<deny verbs="OPTIONS" users="*" />
<deny verbs="TRACE" users="*" />
<deny verbs="HEAD" users="*" />
<deny verbs="PROPFIND" users="*" />
<deny verbs="COPY" users="*" />
<deny verbs="LOCK" users="*" />
<deny verbs="UNLOCK" users="*" />
<deny verbs="PROPPATCH" users="*" />
<deny verbs="MKCOL" users="*" />
<deny verbs="MOVE" users="*" />
<deny verbs="DELETE" users="*" />
</authorization>
</system.web>
Run Code Online (Sandbox Code Playgroud)
但这没有任何想法吗?
所以例如我可以这样做:
$css = new simple_css();
foreach ($css->find_elements_with_property('margin') as $element) {
//do my stuff
if ($something) {
$elem->spacing = '1px';
}
}
$processed_css = $css->plaintext();
Run Code Online (Sandbox Code Playgroud) 我在ASP.Net核心中创建了Wep API以返回PDF.这是我的代码:
public HttpResponseMessage Get(int id)
{
var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
var stream = new System.IO.FileStream(@"C:\Users\shoba_eswar\Documents\REquest.pdf", System.IO.FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "NewTab";
response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
return response;
}
Run Code Online (Sandbox Code Playgroud)
但它只返回JSON响应:
{
"version":{
"major":1,
"minor":1,
"build":-1,
"revision":-1,
"majorRevision":-1,
"minorRevision":-1
},
"content":{
"headers":[
{
"key":"Content-Disposition",
"value":[
"attachment; filename=NewTab"
]
},
{
"key":"Content-Type",
"value":[
"application/pdf"
]
}
]
},
"statusCode":200,
"reasonPhrase":"OK",
"headers":[
],
"requestMessage":null,
"isSuccessStatusCode":true
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?