@if (Request.IsAuthenticated && User.Identity.Name=="administrator")
{
<div id="sidebar">
<div class="module">
<ul class="menu">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
<div class="mainContent">
Hello, @User.Identity.Name !
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的布局,如果用户被认证为管理员,但这种检查看起来不好,我需要检查用户的角色而不是他的名字.
这是控制器方法
public ActionResult AuthenticatedUserLayout(string username)
{
var lst=userContext.UserProfiles.ToList();
var user = lst.Select(u => u.UserName == username);
if(IsAdmin(Session["LoginUser"].ToString())) return View(user); else return Index();
}
Run Code Online (Sandbox Code Playgroud)
我也发现这return View(user)
不好,因为我不知道如何使用它user
.
创建一个基于Windows域用户进行身份验证的ASP.NET MVC应用程序很容易.创建一个使用Entity Framework存储的个人帐户也很容易.事实上,两者都有项目模板.
但我想利用BOTH各种认证在同一应用程序.我试图结合两个项目模板的代码.我在Startup.Auth.cs中遇到问题.
// from "Individual Accounts" template
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
Run Code Online (Sandbox Code Playgroud)
中间件中存在cookie身份验证似乎导致域身份变为未经身份验证.如果我采用此行,域身份验证将起作用.但没有它,我似乎无法支持个人用户帐户.
我已经下载了katana项目源代码并检查了CookieAuthenticationHandler.cs,但我不太明白它是如何在OWIN管道的上下文中工作的.
如何使用ASP.net身份框架允许我的应用程序从Windows域或特定于应用程序的用户存储中验证用户?
c# asp.net-mvc claims-based-identity asp.net-mvc-5 asp.net-identity
我使用Visual Studio 2013 Update 2创建了一个ASP.NET MVC 5应用程序.在应用程序中,我有一个帐户控制器.它与我习惯的不同,并且不包含dbcontext的实例化.
public class AccountController : Controller
{
private ApplicationUserManager _userManager;
public AccountController()
{
}
public AccountController(ApplicationUserManager userManager)
{
UserManager = userManager;
}
public ApplicationUserManager UserManager {
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
private set
{
_userManager = value;
}
}
Run Code Online (Sandbox Code Playgroud)
我web.config
默认创建的是一个像这样的连接字符串:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication3-20140417072624.mdf;Initial Catalog=aspnet-WebApplication3-20140417072624;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释当应用程序第一次启动时应用程序如何知道为此应用程序创建数据库吗?
此外,在后续启动时,它是否使用Entity Framework访问Identity表来进行身份验证?
asp.net asp.net-mvc entity-framework asp.net-mvc-5 asp.net-identity
在MVC/Razor语法中,我试图理解我们需要的原因@RenderBody
.
例如(取自代码示例)
<html>
<head>
<meta charset="utf-8" />
<title>My WebSite</title>
<style>
#container { width: 700px; }
#left { float: left; width: 150px; }
#content { padding: 0 210px 0 160px; }
#right { float: right; width: 200px; }
.clear { clear: both; }
</style>
</head>
<body>
<div id="container">
<div id="left">
@RenderSection("left", required:false)
</div>
<div id="content">
@RenderBody()
</div>
<div id="right">
@RenderSection("right", required:false)
</div>
<div class="clear"></div>
</div>
</body>
</html>
@{
Layout = "~/_3ColLayout.cshtml";
}
<h1>Main Content</h1>
@section …
Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-5
我创建了一个小提琴来演示这个问题(也可以在下面这个问题中运行).
我有一个侧边栏的扑克牌图片,我想拖到一个主要区域.侧边栏包含很多卡片,因此我希望它可以滚动.但是,当我给它一个滚动功能时,当我拖动一张卡片时,当我将它拖出侧边栏时它会被隐藏起来.
var app = angular.module('myApp', ['ngDraggable']);
app.controller('ctrl', function ($scope) {
});
Run Code Online (Sandbox Code Playgroud)
#gallery-container {
overflow-y: scroll;
}
.card {
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://rawgit.com/fatlinesofcode/ngDraggable/master/ngDraggable.js"></script>
<div ng-app="myApp">
<div ng-controller="ctrl">
<div class="row">
<div class="col-xs-3">
<div id="gallery-container">
<div class="row">
<div class="col-sm-12">
<img ng-drag="true" ng-drag-data="hi" ng-drag-success="onDragComplete($data,$event)" ng-center-anchor="true" class="card" src="http://www.download32.com/images/screen/vector_playing_cards-467278.png" alt="">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<img ng-drag="true" ng-drag-data="hi" ng-drag-success="onDragComplete($data,$event)" ng-center-anchor="true" class="card" src="http://www.download32.com/images/screen/vector_playing_cards-467278.png" alt="">
</div>
</div>
<div class="row">
<div class="col-sm-12">
<img ng-drag="true" ng-drag-data="hi" ng-drag-success="onDragComplete($data,$event)" ng-center-anchor="true" class="card" src="http://www.download32.com/images/screen/vector_playing_cards-467278.png" …
Run Code Online (Sandbox Code Playgroud)我的网站用户ERR_SSL_PROTOCOL_ERROR
在发出跨域请求时会看到间歇性的api.flickr.com
间歇性地我的意思是我已经看到这种情况发生在昨天对于api的~1200个请求中的4次.
Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=.....
Run Code Online (Sandbox Code Playgroud)
我的网站是在Google App Engine上运行的AngularJS应用程序,并且在HTTPS上可以使用exclusivley.
sslchecker显示我的网站的证书和证书链已正确安装.好吧,我觉得它看起来还不错!
sslchecker用于api.flickr.com
显示ROOT 1
证书链的缺失.那是问题吗?对我来说有什么方法吗?
还有其他想法吗?问题是我们的证书可能是由不同的权威机构发出的吗?
编辑 -从谷歌分析中收集的其他一些可能相关的信息
我有一个动作过滤器检查是否ID
设置了会话变量.出于开发目的,我在检查之前手动设置了此变量.
public class MyActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext context)
{
context.HttpContext.Session.Add("ID", 123123);
int ID = (int)context.HttpContext.Session.Contents["ID"];
var rd = context.HttpContext.Request.RequestContext.RouteData;
TED _db = new TED();
//if not in DB
if (_db.Users.Find(ID) == null && rd.GetRequiredString("action") != "NoAccess")
{
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("action", "NoAccess");
redirectTargetDictionary.Add("controller", "Home");
redirectTargetDictionary.Add("area", "");
context.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
base.OnActionExecuted(context);
}
}
Run Code Online (Sandbox Code Playgroud)
据我所知,此代码在任何页面之前运行,Session["ID"]
始终设置.如果我一直在测试,该网站工作正常,但如果我离开它一段时间似乎打破,然后尝试继续测试.这是我得到的错误:
int UserID = (int)Session.Contents["ID"];
System.NullReferenceException: Object reference not set to an instance of an object. …
Run Code Online (Sandbox Code Playgroud) 我在web.config中有以下内容:
<customErrors mode="On" defaultRedirect="Error">
<error statusCode="404" redirect="Error/NotFound" />
</customErrors>
Run Code Online (Sandbox Code Playgroud)
我有一个
[HandleError]
Run Code Online (Sandbox Code Playgroud)
在我的HomeController类的顶部.为了测试,我创建了一个简单抛出异常的动作..它重定向到我的
ErrorController/Index
Run Code Online (Sandbox Code Playgroud)
方法,但当它到达我的视图绑定到HandleErrorInfo我的模型为null所以我不知何故失去了对错误的引用.
我确信它与错误在重定向中丢失有关,所以我想看看我是否遗漏了一些东西,如果有人有建议我可以有一个显示Stacktrace和错误消息的视图.
c# asp.net-mvc unhandled-exception asp.net-mvc-4 asp.net-mvc-5
我们正在使用Azure的试用版.我们正在尝试从我们的SQL 2012内部执行跨服务器查询.
我们似乎将我们的本地2012与Azure相关联.当我进入Server Object
- > Linked Servers
在管理工作室时,我看到了我们的Azure
数据库.
但是,如果我尝试打开目录和表,我会收到一条错误消息
Reference to database and/or server name in 'Perseus.sys.sp_tables_rowset2' is not supported in this version of SQL Server
**Perseus是我们目录的名称Azure Sql
.
从本地连接运行查询:
SELECT * FROM [azureDBServer].[Perseus].[dbo].[accounts]
Run Code Online (Sandbox Code Playgroud)
结果是:
OLE DB provider "SQLNCLI11" for linked server "azureDBServer" returned message
"Unspecified error". Msg 40515, Level 16, State 2, Line 1 Reference to database and/or
server name in 'Perseus.sys.sp_tables_info_90_rowset' is not supported in this version of
SQL Server.
Run Code Online (Sandbox Code Playgroud)
内部相同的SQL …
我们面临着必需属性本地化的奇怪错误.
我们有以下代码:
public class AnswersGroupViewModel
{
public int IDAnswerGroup { get; set; }
public int IDEvaluator { get; set; }
public List<AnswersViewModel> Answers { get; set; }
}
public class AnswersViewModel
{
public string Text{ get; set; }
[Required(ErrorMessageResourceName = "RequiredMessage", ErrorMessageResourceType = typeof(Resources.Language))]
public int IDAnswer{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
问题是"RequiredMessage"的正确翻译没有从资源文件中获取,尽管它存在(我们在西班牙语和俄语资源文件上都有RequiredMessage).
像Display这样的属性正在工作和被翻译,但似乎是Required属性的问题.
这是一个示例图像:
使用@ Html.ValidationMessage显示错误
在此先感谢您的帮助.
asp.net-mvc ×7
asp.net ×5
c# ×5
angularjs ×2
javascript ×2
azure ×1
css ×1
html ×1
https ×1
sql-server ×1
ssl ×1
validation ×1