我在我的应用程序中使用ASP.NET身份时出错.
不支持每种类型的多个对象集.对象集"Identity Users"和"Users"都可以包含"Recommendation Platform.Models.ApplicationUser"类型的实例.
我在StackOverflow中看到了一些关于这个错误的问题.全部表示两个DbSet相同类型的对象.但在我看来DbContext有不一样的类型DbSets.FindAsync()在登录期间抛出方法的异常.
if (ModelState.IsValid)
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null && user.IsConfirmed)
{
Run Code Online (Sandbox Code Playgroud)
问题是我没有两个DbSets相同的类型.我的上下文看起来像这样:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public System.Data.Entity.DbSet<RecommendationPlatform.Models.ApplicationUser> IdentityUsers { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和
public class RecContext : DbContext
{
public RecContext()
: base("RecConnection")
{
Database.SetInitializer<RecContext>(new DropCreateDatabaseIfModelChanges<RecContext>());
}
public DbSet<Recommendation> Recommendations { get; set; }
public DbSet<Geolocation> Geolocations { get; set; } …Run Code Online (Sandbox Code Playgroud) 在实体框架代码中,当我声明实体时,我必须使用DbSet <>类型的属性.例如:
public DbSet<Product> Products { get; set; }
public DbSet<Customer> Customers { get; set; }
Run Code Online (Sandbox Code Playgroud)
最近我遇到了声称为虚拟的DbSet <>.
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Customer> Customers { get; set; }
Run Code Online (Sandbox Code Playgroud)
有什么不同?启用了哪些EF功能?
我正在尝试使用反应路由器的browserHistory来测试React组件.为了确保访问browserHistory我正在使用createMemoryHistory(react-router)模块,如下所示:
let createMemoryHistory = require('react-router/lib/createMemoryHistory');
Run Code Online (Sandbox Code Playgroud)
在测试环境中,我正在利用JSDOM库.
global.document = jsdom('');
global.window = document.defaultView;
Run Code Online (Sandbox Code Playgroud)
然后我试图将创建的历史对象分配给DOM:
let history = createMemoryHistory();
global.history = history;
Run Code Online (Sandbox Code Playgroud)
在测试环境中渲染组件时,我遇到以下错误:
不变违规:浏览器历史记录需要DOM
知道如何克服它吗?
我开始使用ngrx/entity包,在那里我可以通过适配器管理存储。有一种addOne方法我想使用,但它将项目添加到集合的末尾。我想在开头添加一个。你能帮我解决这个问题吗?如何在开头添加项目EntityAdapter。
我如何创建实体适配器:
export const adapter: EntityAdapter<AssetTreeNode> = createEntityAdapter({
selectId: (model: AssetTreeNode) => model.Id
});
Run Code Online (Sandbox Code Playgroud)
减速器看起来像这样:
export function reducer(state: AssetListState = initialState, action: AssetListAction) {
switch (action.type) {
(...)
case ASSET_LIST_ADD_ITEM:
let assetToAdd: AssetTreeNode = Object.assign({} as AssetTreeNode,
action.payload.asset,
{ Id: action.payload.createdAssetId });
return adapter.addOne(assetToAdd, state); <--- I wanna add here at the end.
(...)
default:
return state;
}
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用DropDownListFor()时,我找不到为什么我得到NullReferenceException的答案:
视图:
<div class="form-group">
@Html.LabelFor(m => m.Category, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownListFor(
m => m.Category,
new SelectList(Model.CategoryOptionsList, "CategoryOptionId", "Value", Model.CategoryOptionsList.First().CategoryOptionId),
new { @class = "form-control" }
)
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
视图模型:
public class CategoryOption
{
public int CategoryOptionId { get; set; }
public string Value { get; set; }
}
public IEnumerable<CategoryOption> CategoryOptionsList = new List<CategoryOption>
{
new CategoryOption { CategoryOptionId = 0, Value="Rock" },
new CategoryOption { CategoryOptionId = 1, Value="Jazz" },
new CategoryOption { …Run Code Online (Sandbox Code Playgroud) 我在ASP.NET MVC应用程序中使用ASP.NET Identity.将用户添加到角色时出现问题.没有任何异常,但是由于um.AddToRole(),没有向AspNetUserRoles表添加db条目.我的动作方法看起来像这样:
public ActionResult GrantAdmin(string id)
{
ApplicationUser user = um.FindById(id);
if (!rm.RoleExists("admin"))
{
rm.Create(new IdentityRole("admin"));
}
um.AddToRole(user.Id, "admin");
return View((object)user.UserName);
}
Run Code Online (Sandbox Code Playgroud)
um是UserManager类的对象:
private UserManager<ApplicationUser> um = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
Run Code Online (Sandbox Code Playgroud)
这种应用行为的原因是什么?任何的想法?
===编辑===这是我的DbContext:
public ApplicationDbContext()
: base("DefaultConnection")
{
}
Run Code Online (Sandbox Code Playgroud)
和Web.config中的默认连接:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-RecommendationPlatform-20140404055015.mdf;Initial Catalog=aspnet-RecommendationPlatform-20140404055015;Integrated Security=True" providerName="System.Data.SqlClient" />
Run Code Online (Sandbox Code Playgroud) 我已经安装并配置了Prosody服务器.它侦听标准localhost:5222.在配置文件中添加了admin - user1@example.com.对服务器的每个请求都以错误结束:
<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="" version="1.0">
<stream:error>
<not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams"/>
</stream:error>
</stream:stream>
Run Code Online (Sandbox Code Playgroud)
作为客户,我想使用strophe.js.我只发送存在节($ pres).这是我的代码.
'use strict';
angular.module('xmppTestApp')
.controller('ChatCtrl', function () {
var vm = this;
var url = "http://localhost:5222";
var connection = null;
var output = document.getElementById("output");
function log(message) {
var line = document.createElement("div");
line.textContent = message;
output.appendChild(line);
}
function connectHandler(cond) {
if (cond == Strophe.Status.CONNECTED) {
log("connected");
connection.send($pres());
}
else {
log("not connected");
}
}
vm.connectB = function() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
console.info(url); …Run Code Online (Sandbox Code Playgroud) 执行这段代码后,我遇到意外的重定向到localhost:xxxx/Home/null.是什么原因?
这是我的HTML:
<div id="userConsentSection">
Can we use your geolocation? <br />
<input type="button" id="yes" value="Yes" />
<input type="button" id="no" value="No" /><br /><br />
</div>
<div id="setCustomLocationSection">
Enter your address manually.<br />
<input type="text" id="customLocation" />
<input type="button" id="setCustomLocationButton" value="Show" /><br /><br />
</div>
<div id="map" style="height: 450px; width: 720px" />
Run Code Online (Sandbox Code Playgroud)
JS:
var map1 = null;
var location = null;
alert("alert4");
function initialize() {
alert("alert5");
$("#setCustomLocationSection").hide();
var options =
{
center: new google.maps.LatLng(0, 0),
zoom: 2
}
var marker = new …Run Code Online (Sandbox Code Playgroud) 我正在使用Xamarin Studio创建Android应用程序,我遇到了AndroidManifest.xml文件的问题.它不是在'Properties'文件夹中创建的,但我注意到它是在构建后在obj\Debug\android中生成的.我的问题是如何控制生成的文件的内容.我更喜欢直接在AndroidManifest.xml中添加权限,而不是从派生自派生的非抽象类并在其上声明ActivityAttribute(我知道这种可能性).任何想法为什么都不存在于'属性'中?
asp.net-mvc ×4
c# ×3
asp.net ×2
javascript ×2
android ×1
geolocation ×1
google-maps ×1
mocha.js ×1
ngrx ×1
ngrx-entity ×1
prosody-im ×1
react-router ×1
reactjs ×1
redux ×1
roles ×1
strophe ×1
unit-testing ×1
xamarin ×1
xmpp ×1