我正在使用Asp-Team 的ASP.NET Identity Sample,我正在尝试更改数据库IdentityDbContext...
我用构造函数试了一下
public MyDbContext() : base("MyConnectionString") { } // base is IdentityDbContext
Run Code Online (Sandbox Code Playgroud)
和DbContext类一样.
这很有效,直到我尝试注册用户...
await IdentityStore.CreateLocalUser(user, model.Password)
Run Code Online (Sandbox Code Playgroud)
返回false......没有错误,没有.
任何想法如何解决?
编辑:
文件名是Models\AppModel.cs,有MyDbContext class
原来是
public class MyDbContext : IdentityDbContext<MyUser, UserClaim, UserSecret, UserLogin, Role, UserRole>
{
}
Run Code Online (Sandbox Code Playgroud)
我改成了
public class MyDbContext : IdentityDbContext<MyUser, UserClaim, UserSecret, UserLogin, Role, UserRole>
{
public MyDbContext() : base("MyConnectionString") { }
}
Run Code Online (Sandbox Code Playgroud)
连接字符串正在工作,因为我有其他项目使用相同,他们运行正常.
<connectionStrings>
<add name="MySailorContext" connectionString="Data Source=THOMAS-LAPTOP;Initial Catalog=MySailor;Integrated Security=True;Pooling=False;MultipleActiveResultSets=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud) 好吧,我想哈希一个密码,我看看ASP.net Identity在Microsoft.AspNet.Identity.CryptoClass 中是怎么做的,我来了这个函数(用于比较2个密码Hashes):
[MethodImpl(MethodImplOptions.NoOptimization)]
private static bool ByteArraysEqual(byte[] a, byte[] b)
{
if (object.ReferenceEquals(a, b))
{
return true;
}
if (((a == null) || (b == null)) || (a.Length != b.Length))
{
return false;
}
bool flag = true;
for (int i = 0; i < a.Length; i++)
{
flag &= a[i] == b[i];
}
return flag;
}
Run Code Online (Sandbox Code Playgroud)
这是反射器输出的直接复制......
现在我的问题是,NoOptimization属性的优点是什么,为什么它应该存在(如果我删除它会发生什么)?对我来说,它看起来像是一个默认的Equals()实现,直到for-loop.
我试着看一下IL,但这对我来说都是胡说八道:/
我知道VS可以做到这一点,但我不记得操作名称和快捷方式......
Visual Studio执行以下操作:
之前:
string a = "bliblablubb";
string ab = "bliblablubb";
string abc = "bliblablubb";
string abcd = "bliblablubb";
Run Code Online (Sandbox Code Playgroud)
后:
string a = "bliblablubb";
string ab = "bliblablubb";
string abc = "bliblablubb";
string abcd = "bliblablubb";
Run Code Online (Sandbox Code Playgroud)
我目前正在使用VS2013预览版.
我有一个像这样的小功能:
void Bar(string s)
{
*/ do somthing with the string here.*/
}
void Foo()
{
Bar("Hello");
}
Run Code Online (Sandbox Code Playgroud)
如果我看一下IL输出,它给了我以下内容:
.method private hidebysig instance void Foo() cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: ldstr "Hello"
L_0006: call instance void TestApp.MainWindow::Bar(string)
L_000b: ret
}
Run Code Online (Sandbox Code Playgroud)
现在我以为我会替换它的const string字段.
const string str= "Hello";
void Foo()
{
Bar(str);
}
Run Code Online (Sandbox Code Playgroud)
转换为完全相同的 IL片段.
现在我的问题是使用哪一个?
Foo("Hello"); 要么 Foo(cHello);
谢谢您的帮助!
--------------编辑-------------------
更具体地说,我将此用于记录目的以添加前缀消息:它只会在代码中出现一次!
所以它看起来更像是这样的:
void LogDebug(string msg)
{
Log("[DEBUG]", msg)
}
void Log(string pre, string msg)
{ …Run Code Online (Sandbox Code Playgroud) 我迷迷糊糊uppon同样的问题在描述这个问题。此外,我不想从数据库中丢失 __migrationHistory 表。
我使用包含所有 DbSet<> 的“超级”上下文并使用普通上下文的建议解决方案进行了尝试,但出现错误。(“模型支持 DbContext 已更改”)如果您只是从 SQL 服务器中删除 __migrationHistory 表,这很容易避免,但正如我所说,我想保留历史记录。
我找到了一个简单易行的解决方案,请参阅下面的答案。
c# entity-framework ef-code-first entity-framework-migrations
我试图阻止RequestHandler.ParseAll()用await ConsumerTask;,但是当我设置一个断点,我总是第一个获得"完成......"输出...然后Parse2()失败,一个NullReferenceException.(这就是我的猜测:"GC因为_handler超出范围而开始清理")
无论如何,我无法弄清楚为什么会这样.
class MainClass
{
public async void DoWork()
{
RequestHandler _handler = new RequestHandler();
string[] mUrls;
/* fill mUrls here with values */
await Task.Run(() => _handler.ParseSpecific(mUrls));
Console.WriteLine("Done...");
}
}
static class Parser
{
public static async Task<IEnumerable<string>> QueryWebPage(string url) { /*Query the url*/ }
public static async Task Parse1(Query query)
{
Parallel.ForEach(/*Process data here*/);
}
public static async Task Parse2(Query query)
{
foreach(string line in query.WebPage)
/* Here i …Run Code Online (Sandbox Code Playgroud) 免责声明:我编辑了这个问题,因为我改变了这个过程,但它没有改变任何问题......
我试图得到一个PartialViewResult字符串渲染,我试图使用RenderRazorViewToString这个问题的方法渲染视图作为字符串 ...,我从这个qustion mvc返回局部视图的提示作为json
我的问题是,字符串看起来像这样:
<$A$><h1>SomeHeader</h1>
<table</$A$><$B$> class="table table-striped"</$B$><$C$>> <tbody</$C$><$D$> data-bind="template: { name: 'eventTemplate', foreach: events }"</$D$><$E$>></tbody>
</table></$E$>
Run Code Online (Sandbox Code Playgroud)
而不是这个
<h1>SomeHeader</h1>
<table class="table table-striped">
<tbody data-bind="template: { name: 'eventTemplate', foreach: events }"></tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
更新:
流程如下所示:
public ActionResult Index(string item, long id)
{
var cont = SomePartialView(item, id);
return View(model: RenderRazorViewToString(cont));
}
Run Code Online (Sandbox Code Playgroud)
现在View只是渲染字符串,如下所示:
@Model
Run Code Online (Sandbox Code Playgroud)
在RenderRazorViewToString(PartialViewResult)返回这个"跛脚"串...
c# ×7
asp.net-mvc ×2
asp.net ×1
async-await ×1
asynchronous ×1
cil ×1
const ×1
entity-framework-migrations ×1
optimization ×1
parameters ×1
string ×1