我有以下课程:
public static class MetadataManager
{
// assume that it is thread safe
public static List<Field> FieldRegistry { get; set; }
}
public class Field
{
public int ID { get; set; }
public string Name { get; set; }
}
public static class FieldDataValidationManager
{
public static bool Validate(int fieldID)
{
return MetadataManager.FieldRegistry.FirstOrDefault(f => f.ID == fieldID).ID > 1;
}
public static bool Validate(Field field)
{
return fieldID.ID > 1;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,User1和User2同时调用静态方法,并发有什么问题吗?
FieldDataValidationManager.Validate(111)
Run Code Online (Sandbox Code Playgroud)
或者User1正在执行
FieldDataValidationManager.Validate(field1),User2正在执行FieldDataValidationManager.Validate(field2)
我有基于 WebApi 的 Web 服务,例如:
public class ControllerName : ApiController
{
[Route("api/ControllerName/{p1}/{p2}/{p3}/{p4}/{p5}")]
public string GetItemByNameAndId(string p1, string p2, string p3, string p4, string p5)
{
}
}
Run Code Online (Sandbox Code Playgroud)
这种类型的请求正在工作:
主机/api/ControllerName/1/2/3/4/5
但我想要这种类型的请求:
主机/api/控制器名称/&p1=1&p2=2&p3=3&p4=4&p5=5
我收到如下错误:
从客户端 (&) 检测到潜在危险的 Request.Path 值。必须遵循哪些步骤?配置文件中的任何更改、任何属性等。
谢谢你的时间。
我有2个项目的解决方案:Asp.Net WebApi Core和WinForms.我将使用WinForm的服务.
更改了解决方案属性以启动多个项目:第一个WebApi然后是WinForm(主窗体是FORM1).
现在,我有如下的简单代码:
private void button1_Click(object sender, EventArgs e)
{
TestAutentication().Wait();
Console.ReadKey();
}
static async Task TestAutentication()
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("http://localhost:53791");
try
{
HttpResponseMessage response = await client.GetAsync("api/ValuesController");
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsAsync<string>();
Console.WriteLine("{0}", result);
}
else
{
Console.WriteLine("{0}", response.ReasonPhrase);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("{0}", ex.Message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在启动浏览器期间打开然后打开FORM1.在执行该行时单击button1调试器:
HttpResponseMessage response = await client.GetAsync("api/ValuesController");
悬挂的原因是什么?
提前致谢.
c# ×3
asp.net ×1
asp.net-core ×1
async-await ×1
asynchronous ×1
methods ×1
query-string ×1
routing ×1
static ×1