对于我的大多数项目,我都有以下约定:
/src
/Solution.sln
/SolutionFolder
/Project1
/Project2
/etc..
/lib
/Moq
moq.dll
license.txt
/Yui-Compressor
yui.compressor.dll
/tools
/ILMerge
ilmerge.exe
Run Code Online (Sandbox Code Playgroud)
你会注意到,我没有保持外部库中的源文件夹.我也对使用NuGet非常感兴趣,但不希望在源文件夹中使用这些外部库.NuGet是否有设置来更改所有包加载到的目录?
我已经在我的应用程序中实现了对我在互联网上的一些博客文章中阅读的信息后的CSRF攻击的缓解.特别是这些帖子是我实施的驱动力
基本上这些文章和建议说,为了防止CSRF攻击,任何人都应该实现以下代码:
1)添加[ValidateAntiForgeryToken]接受POST Http动词的每个动作
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult SomeAction( SomeModel model ) {
}
Run Code Online (Sandbox Code Playgroud)
2)在<%= Html.AntiForgeryToken() %>向服务器提交数据的表单中添加帮助程序
<div style="text-align:right; padding: 8px;">
<%= Html.AntiForgeryToken() %>
<input type="submit" id="btnSave" value="Save" />
</div>
Run Code Online (Sandbox Code Playgroud)
无论如何,在我的应用程序的某些部分,我正在使用jQuery对服务器进行Ajax POST,而根本没有任何形式.例如,当我让用户点击图像来执行特定操作时,会发生这种情况.
假设我有一个包含活动列表的表.我在表的一列上有一个图像,上面写着"将活动标记为已完成",当用户点击该活动时,我正在进行Ajax POST,如下例所示:
$("a.markAsDone").click(function (event) {
event.preventDefault();
$.ajax({
type: "post",
dataType: "html",
url: $(this).attr("rel"),
data: {},
success: function (response) {
// ....
}
});
});
Run Code Online (Sandbox Code Playgroud)
我如何<%= Html.AntiForgeryToken() %>在这些情况下使用?我应该在Ajax调用的data参数中包含帮助器调用吗? …
我可以用[AcceptVerbs(HttpVerbs.Post)]/[AcceptVerbs(HttpVerbs.Get)]装饰一个动作
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(string title)
{
// Do Something...
}
Run Code Online (Sandbox Code Playgroud)
或者使用[HttpPost]/[HttpGet]属性
[HttpPost]
public ActionResult Create(string title)
{
// Do Something...
}
Run Code Online (Sandbox Code Playgroud)
他们不一样吗?
当我在连续循环中从数据库查询时,一段时间后我收到一个错误:
引发的异常可能是由于瞬态故障引起的.如果要连接到SQL Azure数据库,请考虑使用SqlAzureExecutionStrategy.
通常它工作正常.
我正在调用一个返回包含ac#Anonymous Type对象的List变量的方法.例如:
List<object> list = new List<object>();
foreach ( Contact c in allContacts ) {
list.Add( new {
ContactID = c.ContactID,
FullName = c.FullName
});
}
return list;
Run Code Online (Sandbox Code Playgroud)
我如何在我正在处理的代码中引用此类型属性,例如
foreach ( object o in list ) {
Console.WriteLine( o.ContactID );
}
Run Code Online (Sandbox Code Playgroud)
我知道我的样本是不可能的,我只是这样说,我需要确切地识别匿名类型的每个属性.
谢谢!
方案:
不只是其中一个答案是正确的和/或建议一个有效的解决方案.我最终使用了Greg选项3的答案.我dynamic在.NET 4.0 中学到了一些非常有趣的东西!
我在这里遇到了jsTree.到目前为止,它可以工作,我可以使用[+]图标浏览和扩展节点,并在单击节点时打开页面,但我还是希望它在有人点击某个节点时展开所有直接节点.
我看了看周围至少2个小时但是找不到任何东西.官方网站不是很有帮助,因为他们没有足够的例子,而且没有很好的记录.看看这个,但对我来说也不起作用:http: //luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/2_operations.html
我甚至没有在firebug中收到错误消息
所以这是我的代码现在的样子,树初始化:
$(function () {
$("#jstree").jstree({
....
Run Code Online (Sandbox Code Playgroud)
单击节点触发的功能
.delegate("a","click", function (e) {
//click on node
var page_id = $(this).parent().attr("page_id");
var idn = $(this).parent().attr("id").split("_")[1];
/*
dosnt seem to work either...
$(this).jstree("openNode", $("#node_"+idn));
$(this).jstree("openNode", "#node_"+idn);
*/
page = "index.php?page_id="+page_id;
//location.href = page;
})
Run Code Online (Sandbox Code Playgroud)
.bind也没有工作:
$(this).bind("open_node.jstree", function (event, data) {
if((data.inst._get_parent(data.rslt.obj)).length) {
data.inst._get_parent(data.rslt.obj).open_node(this, false);
}
})
Run Code Online (Sandbox Code Playgroud)
有谁看到我在这里失踪了......?
如何创建运行具有管理员权限的Visual Studio的快捷方式?
实际上我必须导航到Visual Studio开始菜单文件夹,单击带有右边按钮的图标,然后选择"以管理员身份运行".
administrator visual-studio-2010 runas visual-studio-2008 visual-studio
我试图动态确定输入文件的内容/类型.如果我在一个Windows应用程序中,我可以编写这样的代码(来自这个博客)
private string GetContentType(string fileName) {
string contentType = "application/octetstream";
string ext = System.IO.Path.GetExtension(fileName).ToLower();
Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (registryKey != null && registryKey.GetValue("Content Type") != null)
contentType = registryKey.GetValue("Content Type").ToString();
return contentType;
}
Run Code Online (Sandbox Code Playgroud)
还有哪些其他方法更适合MVC应用程序?
我想在Controller.File(...)接收文件路径和内容类型的方法中使用param .
我使用的是plupload 1.3.0版
更具体地说,我如何定义控制器动作来支持分块?我可以HttpPosteFileBase用作参数吗?
目前我正在使用以下代码初始化插件
在HEAD标签中
<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/jquery.ui.plupload.css" )%>" />
<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/gsl.plupload.css" )%>" />
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/gears_init.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/plupload.full.min.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/jquery.ui.plupload.min.js" )%>"></script>
Run Code Online (Sandbox Code Playgroud)
准备好文件
$("#uploader").pluploadQueue({
runtimes: 'html5,html4,gears,flash,silverlight',
url: '<%: Url.Content( "~/Document/Upload" ) %>',
max_file_size: '5mb',
chunk_size: '1mb',
unique_names: true,
filters: [
{ title: "Documenti e Immagini", extensions: "doc,docx,xls,xlsx,pdf,jpg,png" }
],
multiple_queues: false
});
Run Code Online (Sandbox Code Playgroud)