使用ASP.NET Identity 2.0,您如何检查当前登录的用户是否在角色中?我正在使用以下内容,但想知道是否有更高效的东西.
var um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new DbContext()));
var au = um.FindByEmail(Context.User.Identity.GetUserName());
var inrole = um.IsInRole(au.Id, "Admin");
if (inrole)
{
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Azure 函数中获取表单数据。
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
NameValueCollection col = req.Content.ReadAsFormDataAsync().Result;
return req.CreateResponse(HttpStatusCode.OK, "OK");
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
执行函数时出现异常:System.Net.Http.Formatting:没有 MediaTypeFormatter 可用于从媒体类型为“multipart/form-data”的内容中读取“FormDataCollection”类型的对象。
我正在尝试按照此处所述通过 SendGrid 解析入站电子邮件。 https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html
传入的请求看起来是正确的。
--xYzZY 内容配置:表单数据;名称=“附件”
0 --xYzZY 内容配置:表单数据;名称=“文本”
Hello world --xYzZY 内容配置:表单数据;名称=“主题”
主题 --xYzZY 内容配置:表单数据;名称=“到”