我有一个ASP .NET MVC5应用程序,我没有使用Windows身份验证.
一切都工作正常,直到我尝试在开发它的域之外运行应用程序,并且(无论出于何种原因)得到了:
The trust relationship between this workstation and the primary domain failed.
Run Code Online (Sandbox Code Playgroud)
当我想要做的时候User.IsInRole("Admin").
我使用自定义的Identity,Role,IdentityStore,RoleStore,等从.NET的Identity,我可以看到用户和角色数据被从(MongoDB的)数据库中检索正确.
关于这个问题有很多问题,但是他们来自想要使用Windows Auth的人.和模仿他们的MVC应用程序:
那么,SystemException如果我没有使用Active Directory并且(据我所知)没有做任何可能取决于PC域的事情,我为什么要得到这个呢?我错过了一些配置(在我的Web.config或IIS Express中)?
好的,所以缩小了一点......
我的User.IsInRole("Admin")行在if()我的_Layout.cshtml视图中的一个声明中(即,知道在导航栏中显示什么,取决于角色).
我现在知道在没有用户进行身份验证时我只得到上面的错误,而且我不在我用于dev的域中.如果我在该行上放置一个断点,我可以看到该User对象是a System.Security.Principal.WindowsIdentity,它的底层Identity是System.Security.Principal.WindowsIdentity.
另一方面,如果用户被认证,则User对象和ts Identity是System.Security.Claims.ClaimsPrincipal和System.Security.Claims.ClaimsIdentity.
为什么它根本使用Windows身份(未经身份验证时)以及如何禁用它?
将asp.net身份版本1.0.0-rc1与Entity Framework 6.0.0-rc1(Visual Studio 2013 RC附带的那些)一起使用.
试图让用户有机会改变他们的UserName.似乎没有功能AuthenticationIdentityManager,所以我使用EF更改数据(获取当前用户的User对象,更改UserName并保存更改).
问题是认证cookie保持不变,下一个请求失败,因为没有这样的用户.
在过去的表单身份验证中,我使用以下代码来解决此问题.
var formsAuthCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
var isPersistent = FormsAuthentication.Decrypt(formsAuthCookie.Value).IsPersistent;
FormsAuthentication.SetAuthCookie(newUserName, isPersistent);
Run Code Online (Sandbox Code Playgroud)
我该怎么做asp.net身份更新cookie?
UPDATE
以下代码似乎更新了身份验证cookie.
var identity = new ClaimsIdentity(User.Identity);
identity.RemoveClaim(identity.FindFirst(identity.NameClaimType));
identity.AddClaim(new Claim(identity.NameClaimType, newUserName));
AuthenticationManager.AuthenticationResponseGrant = new AuthenticationResponseGrant
(new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = false});
Run Code Online (Sandbox Code Playgroud)
剩下的问题是:如何IsPersistent从当前身份验证cookie中提取值?
我使用Asp.net的身份进行登录,注册,忘记密码等和源代码从该采取以下链接:
现在我有一个UserMaster表,在注册期间我要求以下字段: FullName,EmailId,Password,ContactNumber,Gender.
我的UserMaster包含以下字段:Id,FullName,EmailId,ContactNumber,Gender
现在,当用户提交注册表格时,此FullName,EmailId,ContactNumber,Gender将与电子邮件一起保存在UserMaster中,密码将保存在AspnetUser中.
我的注册方法与上面2个链接中提供的相同.
在这里您可能会注意到我的UserMaster和AspnetUser之间没有任何关系,所以在登录时用户将输入他的电子邮件ID登录我将使用此方法await SignInManager.PasswordSignInAsync验证用户,如果此方法返回成功,那么我将要使用此电子邮件ID并在我的UserMaster中检查此电子邮件,并找到匹配的地方我将从UserMaster获取UserId并将其存储在会话中并使用我的登录方法使用我的应用程序,如下所示:
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
using (var context …Run Code Online (Sandbox Code Playgroud) 我正在使用Visual Studio 2013 RC并使用新Microsoft.AspNet.Identity.*包测试表单身份验证.
我想整合这些概念(用户,角色等),但想要使用我自己的域模型(POCO),它们在不同的程序集中.我也不想创建对Microsoft.AspNet.Identity.*dll 的依赖.
这甚至可能吗?我发现这篇文章说它不是,但这篇文章是基于预览而不是RC版本的身份包编写的.
asp.net-mvc entity-framework owin asp.net-mvc-5 asp.net-identity
我从这里安装了AspNet-identity组件的每晚构建
似乎AuthenticationManagerRC版本的类已从RTM版本(Microsoft.AspNet.Identity.Owin.1.0.0-rtm-130914)中消失.
它曾经在Microsoft.AspNet.Identity.Owin程序集中,但它不再存在.
这个类有方法:SignInAsync并且CheckPasswordAndSignInAsync在创建具有个人用户帐户身份验证的新ASP.Net Web应用程序MVC项目时获得的默认项目中使用.
AuthenticationManager现在在哪里?或者用什么代替?
免责声明:这是我第一次使用ASP.NET MVC 5
我不知道为什么它不起作用.我无法让我的MVC5应用程序授权用户.我在以前的版本(2,3和4)中完成了这个,但我似乎无法在OWIN中使用它.
我正在使用启用了所需功能的本地IIS:

编辑:
我在IIS上使用SSL,在C#上使用RequireHttps
这是代码:
protected void Application_Start()
{
GlobalFilters.Filters.Add(new AuthorizeAttribute());
}
Run Code Online (Sandbox Code Playgroud)
Startup.Auth.cs
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/admin/account/login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseGoogleAuthentication();
Run Code Online (Sandbox Code Playgroud)
即使我使用全局授权,我试图"强制"它,看看这是不是问题:
public class HomeController : Controller
{
[Authorize]
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
没有运气......我不确定OWIN是否有必要,但我甚至尝试过启用表单身份验证:
<authentication mode="Forms" />
Run Code Online (Sandbox Code Playgroud)
编辑[2]
好吧,我发现了问题...... IIS!最后!现在,有人会知道如何解决这个问题吗?在IIS上运行OWIN需要什么特别的东西吗?我现在可以工作,但很快我将不得不部署应用程序,并可能在服务器中遇到同样的问题...
我已经读过这些了:
如何使用AspNet.Identity使用Asp.Net MVC5 RTM位登录/验证用户?
有任何想法吗?
昨晚,我决定尝试将SignalR应用到我的应用程序,因为我使用MVC 5,我不得不使用SignalR的2.0 beta.
哦,男孩,什么时间.昨晚,微软还决定推出所有mvc 5相关软件包的rc1,并且更新打破了一些问题 - 主要是在beta2模板中的帐户控制器中.
public AccountController()
{
IdentityStore = new IdentityStoreManager();
AuthenticationManager = new IdentityAuthenticationManager(IdentityStore);
}
public AccountController(IdentityStoreManager storeManager, IdentityAuthenticationManager authManager)
{
IdentityStore = storeManager;
AuthenticationManager = authManager;
}
public IdentityStoreManager IdentityStore { get; private set; }
public IdentityAuthenticationManager AuthenticationManager { get; private set; }
Run Code Online (Sandbox Code Playgroud)
IdentityStoreManager并且IdentityAuthenticationManager不再被认可.
有没有人成功迁移到rc1了?我找不到MS的任何文档或更新的模板.
由于每个版本的Asp.Net Identity之间有很多变化,有没有办法尽早获得任何即将发生的变化?