道歉并提前感谢您提出这个问题!我还是SO的新手.
我一直在使用MVC5,EF6和VS 2013开发Web应用程序.
一旦发布,我花了一些时间升级到RC位.感谢所有伟大的帖子:例如.解耦Microsoft.AspNet.Identity.*并将asp.net MVC从5.0.0-beta2更新到5.0.0-rc1!
在我无限的智慧中,我决定转向@Hao Kung在这里发布的RTM位:我如何能够及早访问即将到来的Asp.Net Identity变化?.我认为当我们最终收到RTM版本时,我会省去麻烦并且不会太落后.
这可能是一场噩梦,或者我只是完全遗漏了某些东西(或两者兼而有之),因为我无法弄清楚曾经使用RC1的基本任务.
虽然我似乎是通过控制器登录用户(Asp.Net Identity RTM版本中的Microsoft.AspNet.Identity.Owin.AuthenticationManager在哪里?)...我的WindowsIdentity始终为空,在我调用SignIn后未经过身份验证.正确填充了user和claimIdentity对象.
这是我调用的操作方法(为了完整性将属性移动到局部变量):
[HttpPost, AllowAnonymous, ValidateAntiForgeryToken]
public virtual async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid) {
var userManager = new UserManager<EtdsUser>(new UserStore<EtdsUser>(new EtdsContext()));
var user = userManager.Find(model.UserName, model.Password);
if (user != null) {
var authenticationManager = HttpContext.GetOwinContext().Authentication;
authenticationManager.SignOut(new[] {DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.ExternalBearer});
var claimsIdentity = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties { IsPersistent = model.RememberMe}, claimsIdentity);
return RedirectToLocal(returnUrl);
}
}
ModelState.AddModelError("", "The …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用了OWIN身份验证.
登录操作
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, result.UserFirstName));
claims.Add(new Claim(ClaimTypes.Sid, result.UserID.ToString()));
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
Run Code Online (Sandbox Code Playgroud)
我想从不同的操作访问UserName和UserID.如何访问声明中添加的值?
更新 我试过了
var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, result.UserFirstName + " " + result.UserLastName));
claims.Add(new Claim(ClaimTypes.Sid, result.UserIDNumber.ToString()));
var identity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
var authenticationManager = Request.GetOwinContext().Authentication;
authenticationManager.SignIn(identity);
var claimsPrincipal = new ClaimsPrincipal(identity);
Thread.CurrentPrincipal = claimsPrincipal;
Run Code Online (Sandbox Code Playgroud)

我可以在快速窗口中查看值.但即使我无法访问该值.如何获得价值?
一切都习以为常,直到fb将api升级到2.4 (我以前的项目中有2.3).
今天当我在fb开发人员上添加一个新的应用程序时,我得到了api 2.4.
问题:现在我从fb(loginInfo.email = null)收到空电子邮件.
当然,我检查了用户电子邮件在fb配置文件中处于公共状态,
我去了loginInfo对象,但没有找到任何其他电子邮件地址.
我谷歌,但没有找到任何答案.
请任何帮助..我有点迷路..
谢谢,
我的原始代码(适用于2.3 api):
在AccountController.cs中:
//
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Login");
}
//A way to get fb details about the log-in user:
//var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name"); <--worked only on 2.3
//var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:name"); <--works on 2.4 api …Run Code Online (Sandbox Code Playgroud) c# facebook facebook-graph-api asp.net-mvc-5 asp.net-identity-2
我正在探索SignInManager类.但MSDN上提供的信息非常无用.它只说明提供的方法和属性.
我要找的是,
1)什么是SignInManager?2)如何使用它?3)我有自己的数据库,其中包含凭据相关信息(用户名和密码)
我如何使用SignInmanager以及如何使用它,以便我的自定义数据库用于验证用户?
我使用的是asp.net MVC 5和Visual Studio 2015.在我的示例项目中,我有一个包含操作方法的帐户控制器
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用它,MSDN完全没用提供这方面的信息.任何有用的链接都会详细解释它,因为我不知道SignInManager是什么以及它的用途.
谢谢
使用CssRewriteUrlTransform时,MVC的捆绑在CSS图像中返回错误的URL:
我有一个内联网应用程序,其URL是,例如:http://usid01-srv002/MyApplication.它位于IIS的"默认网站"中.
其中包含以下内容BundleConfig.cs:
bundles.Add(new StyleBundle("~/bundles/jcss")
.Include("~/Scripts/JQueryUI/css/*.css", new CssRewriteUrlTransform())
);
Run Code Online (Sandbox Code Playgroud)
捆绑系统为这些CSS文件中引用的任何图像生成错误的URL,从而产生404甚至JQueryUI经过良好测试的CSS文件(来自FireBug):

例如,它正在产生
http://usid01/path/foo.png
Run Code Online (Sandbox Code Playgroud)
什么时候应该生成:
http://usid01/MyApplication/path/foo.png
Run Code Online (Sandbox Code Playgroud)
如何让捆绑系统生成指向正确位置的URL?
css asp.net-mvc relative-path bundling-and-minification asp.net-mvc-5
我似乎很难得到一些应该很容易的东西.在我看来,使用Razor,我想得到当前控制器的名称.例如,如果我在这里:
http://www.example.com/MyController/Index
Run Code Online (Sandbox Code Playgroud)
如何MyController从Razor表达式获取控制器名称:
@* Obviously this next line doesn't work
@Controller.Name
*@
Run Code Online (Sandbox Code Playgroud)
我是MVC的新手,所以如果这是一个明显的答案,请不要攻击我.
我是ASP.NET MVC的新手,我一直在开发一个带有个人用户身份验证的MVC 5应用程序.在做我的应用程序时,我一直在做分层模式,比如分离模型层,DAL层,Repos等等.但是现在在MVC 5中,我希望能够使用他们称之为Identity的用户和角色管理和身份验证,然后仍然有我的应用程序的分层结构,因为现在似乎Identity与MVC项目本身,其中的用户和角色模型以及上下文相结合.
我现在在我的应用程序中所做的是我在MVC项目(在单独的文件夹中)中拥有所有我应该要分离的层,如我的DAL,UnitOfWork,Repos,其他模型等,只是为了使它工作,现在.我知道这不是正确的做法.
所以,任何人都可以向我指出一些关于这个的好例子或文章,或者直接解释它是否可能以及如何?Google对此并不友好.谢谢!
好吧,这不是什么大不了的事,但它让我烦恼,我不能放手.
所以我使用MVC 5.1与.NET 4.5.1和OWIN身份验证.因此,当您创建新的MVC 5项目时,以下内容会自动添加到Web.config中以删除表单身份验证http模块,因为在使用OWIN中间件时不再需要它:
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
现在,因为我们正在删除模块,这意味着它之前已添加,所以这里是注册此http模块的条目C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config:
<httpModules>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</httpModules>
Run Code Online (Sandbox Code Playgroud)
这里是C:\Windows\System32\inetsrv\config\applicationHost.configIIS 8.5 的条目,告诉我的应用程序使用该模块:
<system.webServer>
<modules>
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="managedHandler" />
</modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
因此,在应用程序级别自动添加到我的Web配置的名称属性为"FormsAuthenticationModule",而两个服务器级别/ asp.net级别配置文件中的条目使用名称属性"FormsAuthentication".那么这里发生了什么?在我看来,由于name属性不匹配,因此不会删除该模块.我只是认为这是一个错字,但在网上搜索后,每个人似乎都在应用程序web.config中使用"FormsAuthenticationModule".这是最新版本的asp.net/iis的最新变化还是我错过了什么?
我有我在VS 2013中创建的MVC 5应用程序.现在我正在尝试部署此应用程序,我有一个问题:我可以在4.0 .Net Framework的服务器上部署MVC 5吗?
我只是创建部署包,我试图在IIS中导入此包.它说"导入成功",但当我尝试"浏览"网站它说:
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Run Code Online (Sandbox Code Playgroud)
我刚检查过Directory Browsing,它Enabled在IIS中
我想知道如果有一种方法与重置密码UserManager的ASP.NET MVC 5
我尝试使用已经有密码但没有成功的用户.任何线索?
IdentityResult result = UserManager.AddPassword(forgotPasswordEvent.UserId.ToString(), model.ConfirmPassword);
if (result.Succeeded)
{
//
}
else
{
AddErrors(result);
}
Run Code Online (Sandbox Code Playgroud) asp.net-mvc-5 ×10
c# ×8
asp.net-mvc ×5
asp.net ×4
.net ×2
owin ×2
claims ×1
css ×1
facebook ×1
iis-8 ×1
passwords ×1
razor ×1
usermanager ×1