有没有人可以帮助我如何在ASP中使用特殊字符?净身份?问题是我的用户不能用特殊字符注册:塞尔维亚,塞尔维亚,塞尔维亚,塞尔维亚,塞尔维亚。当你尝试在注册中输入这些字符时,我得到以下错误:用户名Krešo无效,只能包含字母或数字。
我可以在哪里以及如何改变这个。
代码如下:
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Pages_Account_Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPrijava_Click(object sender, EventArgs e)
{
UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();
userStore.Context.Database.Connection.ConnectionString =
System.Configuration.ConfigurationManager.ConnectionStrings["SeminariConnectionString3"].ConnectionString;
UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);
IdentityUser user = new IdentityUser();
user.UserName = txtKorisnickoIme.Text;
if(txtLozinka.Text == txtPotvrdaLozinke.Text)
{
try
{
IdentityResult result = manager.Create(user, txtLozinka.Text);
if(result.Succeeded)
{
var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties(), userIdentity);
Response.Redirect("Pocetna.aspx");
}
else
{
litStatus.Text = result.Errors.FirstOrDefault();
}
}
catch (Exception ex)
{
litStatus.Text = ex.ToString();
}
}
else
{
litStatus.Text = "Lozinke moraju biti identične.";
}
}
}
您应该能够按照以下方式更改此行为:
var manager = new UserManager<IdentityUser>(userStore); // existing code
var validator = manager.UserValidator as UserValidator<ApplicationUser>;
if (validator != null) validator.AllowOnlyAlphanumericUserNames = false;
如果validator
结果为null,则稍微调试一下以找到运行时使用的实际类型