我按字母顺序排序了大量字符串(最多1M).我已经使用HashSet,SortedDictionary和Dictionary对这个集合进行了LINQ查询.我是静态缓存集合,它的大小高达50MB,我总是在缓存集合中调用LINQ查询.我的问题如下:
无论集合类型如何,性能都比SQL差很多(最多200ms).对基础SQL表执行类似的查询时,性能要快得多(5-10ms).我已经实现了我的LINQ查询,如下所示:
public static string ReturnSomething(string query, int limit)
{
StringBuilder sb = new StringBuilder();
foreach (var stringitem in MyCollection.Where(
x => x.StartsWith(query) && x.Length > q.Length).Take(limit))
{
sb.Append(stringitem);
}
return sb.ToString();
}
Run Code Online (Sandbox Code Playgroud)
据我所知,HashSet,Dictionary等使用二叉树搜索而不是标准枚举来实现查找.对于高级集合类型的高性能LINQ查询,我有哪些选择?
我正在向混合WebForms/MVC站点添加一些UI功能.在这种情况下,我将一些AJAX UI功能添加到WebForms页面(通过jQuery),数据来自MVC JsonResult.一切都在100%工作,但有一个例外:
我想实现AntiForgeryToken的XSRF保护.我已经将它与我的纯MVC应用程序上的ValidateAntiForgeryToken属性结合使用,但是想知道如何在WebForms中实现Html.AntiForgeryToken()方法. 以下是使用UrlHelper的示例.
我正确地将ViewContext/RequestContext"模拟"起来有些麻烦.我应该如何在WebForms页面中使用HtmlHelpers?
编辑:我想从我的WebForms页面检索AntiForgeryToken,而不是从MVC JsonResult.
我正在使用ActionFilterAttribute来执行自定义身份验证逻辑.该属性仅用于包含我的身份验证逻辑的派生Controller类.
这是我的控制器,源自我的自定义控制器类,以及一个示例属性:
public class MyController : CustomControllerBase
{
[CustomAuthorize(UserType = UserTypes.Admin)]
public ActionResult DoSomethingSecure()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的ActionFilterAttribute的一个例子:
public class CustomAuthorizeAttribute : ActionFilterAttribute
{
public MyUserTypes UserType { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
myUser user = ((CustomControllerBase)filterContext.Controller).User;
if(!user.isAuthenticated)
{
filterContext.RequestContext.HttpContext.Response.StatusCode = 401;
}
}
}
Run Code Online (Sandbox Code Playgroud)
效果很好.
这是一个问题:我是否可以要求此属性仅用于我的自定义控制器类型中的操作?
我有以下代码:
private void GetRequestStreamCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
// End the operation
Stream postStream = request.EndGetRequestStream(asynchronousResult);
//Console.WriteLine("Please enter the input data to be posted:");
//string postData = Console.ReadLine();
string postData = "my data";
// Convert the string into a byte array.
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Write to the request stream.
postStream.Write(byteArray, 0, postData.Length);
postStream.Close();
// Start the asynchronous operation to get the response
IAsyncResult result =
(IAsyncResult)request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
private void GetResponseCallback(IAsyncResult asynchronousResult)
{
HttpWebRequest request …
Run Code Online (Sandbox Code Playgroud) 我知道如何使用MVC的AntiForgeryToken属性以及它的关联HTML帮助程序来帮助XSRF保护我的应用程序的表单POST.
可以为实现GET的JsonResults做类似的事情吗?
例如,我的View包含一个onSubmit jQuery调用,如下所示:
$.getJSON("/allowActivity/YesOrNo/" + someFormValue, "{}", function(data) {
if(data.Allow) {
//Do something.
}
});
Run Code Online (Sandbox Code Playgroud)
我想确定这个JsonResult只能从目标页面调用.
编辑:
我发现这个帖子关于一个类似的问题,没有具体的答案.
确保我的GET(非破坏性)URL仅由我自己的页面中的AJAX调用消耗的最简单方法是什么?
我想使用SMTP客户端uiing microsft.net以C#作为编程语言发送电子邮件.但对于通过SMTP客户端发送的电子邮件,我们是否可以添加"无转发"或"无复制"等安全功能.我不希望电子邮件的收件人转发或复制电子邮件的内容.
我试图以不同的方式初始化构造函数,如果它使用符合特定条件的参数调用,并且我有以下代码.
class MessageEventArgs : EventArgs
{
private int _pId;
private string _message;
private string _channelPath;
public MessageEventArgs(string message)
{
_pId = Process.GetCurrentProcess().Id;
_message = message;
_channelPath = null;
}
public MessageEventArgs(string[] details)
{
if (details.Length == 1)
{
new MessageEventArgs(details[0]);
return;
}
_pId = int.Parse(details[0]);
_message = details[1];
_channelPath = details[2];
}
}
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,在逐行调试和逐步调试时,我看到所有调用都正常,但在实例化之后,pId
并且_message
具有默认值,即0和null
c# ×5
asp.net-mvc ×3
.net ×2
constructor ×1
csrf ×1
email ×1
html-helper ×1
jquery ×1
linq ×1
lotus-notes ×1
performance ×1
smtp ×1
webforms ×1