如何在Microsoft.AspNet.Identity.UserManager上设置AllowOnlyAlphanumericUserNames标志,以便UserValidator将允许非字母数字用户名?
我正在尝试检索作为OnAuthenticated上下文返回的用户属性,并在此示例后添加为声明: 如何使用ASP.NET身份(OWIN)访问Facebook私人信息?
我可以看到我期望的数据是在登录时返回的,并且在Starup.Auth.cs中被添加为声明.但是,当我在帐户控制器内时,UserManager或UserStore中出现的唯一声明由LOCAL AUTHORITY颁发.Facebook(或其他外部提供商)无法找到任何索赔.在上下文中添加的声明到底在哪里?(我正在使用VS2013 RTM.)
Azure上的完整源代码和实时站点链接到这里:https://github.com/johndpalm/IdentityUserPropertiesSample/tree/VS2013rtm
这是我在Startup.Auth.cs中的内容:
var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions()
{
AppId = ConfigurationManager.AppSettings.Get("FacebookAppId"),
AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"),
Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider()
{
OnAuthenticated = (context) =>
{
const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
foreach (var x in context.User)
{
var claimType = string.Format("urn:facebook:{0}", x.Key);
string claimValue = x.Value.ToString();
if (!context.Identity.HasClaim(claimType, claimValue))
context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook"));
}
context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook"));
return Task.FromResult(0);
}
}
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
Run Code Online (Sandbox Code Playgroud)
捕获外部登录属性的另一种方法是为访问令牌添加单个声明并使用属性填充它:
const string XmlSchemaString = "http://www.w3.org/2001/XMLSchema#string";
var …
Run Code Online (Sandbox Code Playgroud) 我试图将一个或多个文件(.doc)发送到ASP.NET Web API 2服务并返回修改后的版本(.docx).我能够发送文件并获得响应,但我在请求中的HTTPContent服务中使用的HttpContentMultipartExtensions在客户端中无法用于响应.这是开箱即用的可以接线的东西,还是滥用多部分?
有两个应用程序:MVC客户端和Web API服务:
Controller for Client(从App_Data读取样本文件,从POST到serviceserver/api/mpformdata):
public async Task<ActionResult> PostMpFormData()
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath(@"~\App_Data"));
var files = dir.GetFiles().ToList();
using (HttpClient client = new HttpClient())
{
HttpResponseMessage result = new HttpResponseMessage();
using (MultipartFormDataContent mpfdc = new MultipartFormDataContent())
{
foreach (var file in files)
{
mpfdc.Add(new StreamContent(file.OpenRead()), "File", file.Name);
}
var requestUri = ConfigurationManager.AppSettings["DocumentConverterUrl"] + "/api/mpformdata";
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("multipart/form-data"));
result = client.PostAsync(requestUri, mpfdc).Result;
}
ViewBag.ResultStatusCode = result.StatusCode;
ViewBag.ContentLength = result.Content.Headers.ContentLength;
// Fiddler show that it returns multipartform content, …
Run Code Online (Sandbox Code Playgroud)