我有一个 C# 应用程序,它对包含计算的源文件执行一些运行时编译到动态程序集中。显然,这是一个严重的安全问题。
从下面的“公式”,将生成下面的代码,并创建一个动态程序集:
公式:
Int32 _index = value.LastIndexOf('.');
String _retVal = value.Substring(_index + 1);
return _retVal;
Run Code Online (Sandbox Code Playgroud)
生成的代码:
using System;
namespace Dynamics
{
public class Evaluator
{
public Object Evaluate(String value)
{
// Begin external code
Int32 _index = value.LastIndexOf('.');
String _retVal = value.Substring(_index + 1);
return _retVal;
// End external code
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后加载动态程序集并通过反射执行 Evaluate 方法。这很好用。
问题是恶意代码注入的可能性很大,所以我想在“沙盒”线程(没有任何非托管 API 调用)中运行 Evaluate 方法。出于测试目的,我使用内置的匿名 Windows 用户,并提供了以下代码:
Thread tSandbox = new Thread(
new ParameterizedThreadStart(this.DoSandboxedEvaluation));
WindowsIdentity tIdentity = WindowsIdentity.GetAnonymous();
WindowsPrincipal tPrincipal = new …
Run Code Online (Sandbox Code Playgroud) 我正在尝试找到一种可靠的方法来唯一地识别和跟踪ASP.NET网站中的不同HttpRequests.
有没有人知道HttpRequest.GetHashCode()的实现?具体来说,碰撞发生的频率如何?
我知道HashCodes不保证是唯一的.我试图理解的是统计上我经常会发现HashCode重复的频率.
我想到的系统会优雅地处理HashCode冲突,但我想确保它们至少与1000中左右的1一样独特.
我有一张有100万+记录的大桌子.不幸的是,创建该表的人决定将日期放在一个varchar(50)
字段中.
我需要做一个简单的日期比较 -
datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
Run Code Online (Sandbox Code Playgroud)
但它失败了convert()
:
Conversion failed when converting datetime from character string.
Run Code Online (Sandbox Code Playgroud)
显然,它不喜欢那个领域的东西,而且由于记录太多,我不能仅仅通过观察就知道.如何正确清理整个日期字段,以便它不会失败convert()
?这就是我现在拥有的:
select count(*)
from MyTable
where
isdate(lastUpdate) > 0
and datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我并不关心性能.这将是一次性查询.不能将表更改为日期时间字段.
我已经尝试添加第三个参数,它没有任何区别.
问题很可能是数据的存储方式,只有两种安全格式; ISO YYYYMMDD; ISO 8601 yyyy-mm-dd Thh:mm:ss:mmm(无空格)
isdate()
检查不会照顾这个吗?
我不需要100%的准确性.我只想获得过去30天的大部分记录.
select isdate('20080131') -- returns 1
select isdate('01312008') -- returns 0
Run Code Online (Sandbox Code Playgroud)
将CASE和ISDATE放在CONVERT()函数中.
谢谢!这样做了.
在.NET中,如果有人将非法值传递set { }
给属性的某个部分,应该抛出什么类型的异常?
例:
public string Provider
{
get { return _provider; }
set
{
if (String.IsNullOrEmpty(value)) throw new Exception("Provider cannot be null or empty."); //what type of exception should be thrown here instead?
_provider = value;
}
}
Run Code Online (Sandbox Code Playgroud)
注意:
我问这个问题,因为它适用于.NET,但它也适用于许多其他语言.因此,如果您有一个适用于.NET框架之外的其他问题的好答案,请发布!
.net ×3
asp.net ×1
c# ×1
datetime ×1
exception ×1
hashcode ×1
reflection ×1
sandbox ×1
security ×1
sql-server ×1