我有一个类库(在C#中).我需要使用HtmlEncode方法对数据进行编码.这很容易从Web应用程序.我的问题是,如何从从控制台应用程序调用的类库中使用此方法?
用.NET语言编写的所有代码都编译为MSIL,但是只有使用MSIL才能直接执行特定的任务/操作吗?
让我们在MSIL中比C#,VB.NET,F#,j#或任何其他.NET语言更容易完成.
到目前为止我们有这个:
raise
元素定义事件.main()
方法作为.entrypoint
.int
和本机unsigned int
类型.protected internal
是fam 或 assem)<Module>
类以定义全局函数或模块初始值设定项.我有一个案例,使用JOIN或IN将给我正确的结果......通常有更好的性能,为什么?它取决于您运行的数据库服务器多少钱?(仅供参考我使用的是MSSQL)
我正在进行php登录,我正在尝试决定是否使用SHA1或Md5,或者我在另一篇stackoverflow文章中读到的SHA256.他们中的任何一个比其他人更安全吗?对于SHA1/256,我还使用盐吗?
另外,这是一种将密码存储为mysql中的哈希的安全方法吗?
function createSalt()
{
$string = md5(uniqid(rand(), true));
return substr($string, 0, 3);
}
$salt = createSalt();
$hash = sha1($salt . $hash);
Run Code Online (Sandbox Code Playgroud) int[] myIntegers;
myIntegers = new int[100];
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,是新的int [100]在堆上生成数组吗?从我通过c#读到的CLR,答案是肯定的.但我无法理解的是,数组中的实际int会发生什么.由于它们是值类型,我猜它们必须被装箱,因为我可以,例如,将myIntegers传递给程序的其他部分,如果它们一直留在堆栈上它会使堆栈混乱.还是我错了?我猜他们只是盒装,并且只要数组存在就会活在堆上.
在查看各种C#异步CTP示例时,我看到一些返回的异步函数void
,以及其他返回非泛型函数的异步函数Task
.我可以看到为什么返回a Task<MyType>
对于在异步操作完成时将数据返回给调用者很有用,但是我看到的返回类型的函数Task
永远不会返回任何数据.为什么不回来void
?
在C#6中有一个新功能:插值字符串.
这些允许您将表达式直接放入代码中,而不是依赖于索引:
string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y());
Run Code Online (Sandbox Code Playgroud)
变为:
string s = $"Adding \"{x}\" and {this.Y()} to foobar.";
Run Code Online (Sandbox Code Playgroud)
但是,我们在使用逐字符串(主要是SQL语句)的多行中有很多字符串,如下所示:
string s = string.Format(@"Result...
Adding ""{0}"" and {1} to foobar:
{2}", x, this.Y(), x.GetLog());
Run Code Online (Sandbox Code Playgroud)
将这些恢复为常规字符串似乎很麻烦:
string s = "Result...\r\n" +
$"Adding \"{x}\" and {this.Y()} to foobar:\r\n" +
x.GetLog().ToString();
Run Code Online (Sandbox Code Playgroud)
如何同时使用逐字和插值字符串?
使用Powershell v3的Invoke-WebRequest和Invoke-RestMethod我已成功使用POST方法将json文件发布到https网站.
我正在使用的命令是
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("cert.crt")
Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Body $json -ContentType application/json -Method POST
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用GET方法时:
Invoke-WebRequest -Uri https://IPADDRESS/resource -Credential $cred -certificate $cert -Method GET
Run Code Online (Sandbox Code Playgroud)
返回以下错误
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:8 char:11
+ $output = Invoke-RestMethod -Uri https://IPADDRESS/resource -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用以下代码来忽略SSL证书,但我不确定它是否真的在做任何事情.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Run Code Online (Sandbox Code Playgroud)
有人可以提供一些指导,说明这里可能出现的问题以及解决方法吗?
谢谢
我在我创建的Web API中进行了以下操作:
// GET api/<controller>
[HttpGet]
[Route("pharmacies/{pharmacyId}/page/{page}/{filter?}")]
public CartTotalsDTO GetProductsWithHistory(Guid pharmacyId, int page, string filter = null ,[FromUri] bool refresh = false)
{
return delegateHelper.GetProductsWithHistory(CustomerContext.Current.GetContactById(pharmacyId), refresh);
}
Run Code Online (Sandbox Code Playgroud)
对此Web服务的调用是通过以下方式通过Jquery Ajax调用完成的:
$.ajax({
url: "/api/products/pharmacies/<%# Farmacia.PrimaryKeyId.Value.ToString() %>/page/" + vm.currentPage() + "/" + filter,
type: "GET",
dataType: "json",
success: function (result) {
vm.items([]);
var data = result.Products;
vm.totalUnits(result.TotalUnits);
}
});
Run Code Online (Sandbox Code Playgroud)
我见过一些以这种方式实现上一个操作的开发人员:
// GET api/<controller>
[HttpGet]
[Route("pharmacies/{pharmacyId}/page/{page}/{filter?}")]
public async Task<CartTotalsDTO> GetProductsWithHistory(Guid pharmacyId, int page, string filter = null ,[FromUri] bool refresh = false)
{
return …
Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×2
ajax ×1
arrays ×1
async-await ×1
async-ctp ×1
asynchronous ×1
c#-6.0 ×1
cil ×1
clr ×1
git ×1
heap ×1
html-encode ×1
https ×1
jquery ×1
login ×1
md5 ×1
memory ×1
performance ×1
php ×1
powershell ×1
rest ×1
return-type ×1
sha1 ×1
sha256 ×1
sql ×1
sql-server ×1
stack ×1
t-sql ×1