我不知道如何为C#数据模型制作自定义setter.场景非常简单,我希望我的密码能够使用SHA256功能自动加密.SHA256功能非常有效(我以前曾在大量的项目中使用过).
我已经尝试了几件事,但是当我运行时update-database
,似乎它正在递归地执行某些操作并且我的Visual Studio挂起(不发送错误).请帮助我了解如何在模型中默认加密密码.
public class Administrator
{
public int ID { get; set; }
[Required]
public string Username { get; set; }
[Required]
public string Password
{
get
{
return this.Password;
}
set
{
// All this code is crashing Visual Studio
// value = Infrastructure.Encryption.SHA256(value);
// Password = Infrastructure.Encryption.SHA256(value);
// this.Password = Infrastructure.Encryption.SHA256(value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
种子
context.Administrators.AddOrUpdate(x => x.Username, new Administrator { Username = "admin", Password = "123" });
Run Code Online (Sandbox Code Playgroud) 我一直在WebApi2上阅读很多,我真的很喜欢它,但我只是不明白为什么每个方法都使用async
而不是标准方法.
这是一个例子:
[ResponseType(typeof(BookDto))]
public async Task<IHttpActionResult> GetBook(int id)
{
BookDto book = await db.Books.Include(b => b.Author)
.Where(b => b.BookId == id)
.Select(AsBookDto)
.FirstOrDefaultAsync();
if (book == null)
{
return NotFound();
}
return Ok(book);
}
Run Code Online (Sandbox Code Playgroud)
这有什么好处?我仍然需要等待我的书在使用之前使用ef从db加载.这有什么不同于我不使用任务来检索书籍的常规方式吗?
当我在Admin
区域内并使用属性路由映射我的路线时,它找不到视图,因为它不会查看实际区域视图文件夹,而只查看全局视图文件夹.
只有当我通过完整路径查看它然后才能显示它,否则它会抛出我的错误.
错误
The view 'Authorize' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Authorize.aspx
~/Views/Home/Authorize.ascx
~/Views/Shared/Authorize.aspx
~/Views/Shared/Authorize.ascx
~/Views/Home/Authorize.cshtml
~/Views/Home/Authorize.vbhtml
~/Views/Shared/Authorize.cshtml
~/Views/Shared/Authorize.vbhtml
Run Code Online (Sandbox Code Playgroud)
码
[RoutePrefix("admin")]
public class HomeController : Controller
{
[Route]
public ActionResult Index()
{
return View("Authorize"); // Error
return View("~/Areas/Admin/Views/Home/Authorize.cshtml"); // Working
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,如果我禁用属性路由并切换回旧的路由,它将起作用.有什么方法可以解决这个问题,或者它是按照预期的方式工作的,我应该在所有方面应用完整的路径?
c# asp.net-mvc asp.net-mvc-areas attributerouting asp.net-mvc-5
我不明白我在哪里可以找到我编译的包,所以我可以将它复制到我的设备并从那里安装.
我做的是创建一个空项目,然后在没有错误的情况下构建它,但是,我找不到.apk
文件.
\platforms\android\bin
有HelloWorld-debug.apk
,但我不想调试包,但一个正常的一个.
我尝试过phonegap build android
,并且phonegap build android local
在这两个命令之间没有发现任何差异.另外,为什么HelloWorld
我命名为我的项目lololol
?
我正在尝试使用Mono和XSP4在我的Linux机器上启动MVC5网站.它适用于没有视图但是当我尝试渲染某些东西时它会给我带来错误.
这是我的测试代码.请注意,我没有更改任何内容,这基本上是没有EF或任何其他库的空白站点.只是裸骨MVC5 +剃刀.
public ActionResult Index()
{
// return Content("'sall good"); // works
return View();
}
Run Code Online (Sandbox Code Playgroud)
System.InvalidOperationException
找不到Razor Host Factory类型:System.Web.Mvc.MvcWebRazorHostFactory,System.Web.Mvc,Version = 5.0.0.0,Culture = neutral,PublicKeyToken = 31BF3856AD364E35
描述:HTTP 500.Error处理请求.
详细信息:非Web异常.异常来源(应用程序或对象的名称):System.Web.WebPages.Razor.
堆栈跟踪
at System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory (System.String typeName) [0x00000] in <filename unknown>:0
at System.Collections.Concurrent.ConcurrentDictionary`2+<GetOrAdd>c__AnonStorey3[System.String,System.Func`1[System.Web.WebPages.Razor.WebRazorHostFactory]].<>m__0 () [0x00000] in <filename unknown>:0
at (wrapper delegate-invoke) System.Func`1<System.Collections.Generic.KeyValuePair`2<string, System.Func`1<System.Web.WebPages.Razor.WebRazorHostFactory>>>:invoke_TResult__this__ ()
...
Run Code Online (Sandbox Code Playgroud)
我试图将Version = 5.0.0.0更改为4.0.0.0和3.0.0.0等但没有任何作用.我现在仍然得到同样的错误,大约是4.0.0.0.
有什么希望吗?
我有一个非常简单的应用程序,生成方程式,非常简单的,如
4 + 5 = x
x + 4 = 12
15 / x = 3
x^2 = 4
sqrt(6) = x
当我把它显示给我自己的方程式x + 4 = 12
就好了,我可以读得很好但是如果它会x^2 = 4
显示为x 2 = 4 会很好.它不一定是图像,它可能是其他任何东西,但它应该这样用户可以理解方程式.
是否有一些图书馆可以帮助我?
我想创建一个线程,然后将参数传递给它.但我不知道怎么做.
Thread siteDownloader = new Thread(new ParameterizedThreadStart(GetHTML));
Run Code Online (Sandbox Code Playgroud)
这是我想作为新线程启动的功能.
static string GetHTML(string siteURL)
{
WebClient webClient = new WebClient();
try
{
string sitePrefix = siteURL.Substring(0, 7);
if (sitePrefix != "http://")
{
siteURL = "http://" + siteURL;
}
}
catch
{
siteURL = "http://" + siteURL;
}
try
{
return webClient.DownloadString(siteURL);
}
catch
{
return "404";
}
}
Run Code Online (Sandbox Code Playgroud) 我需要创建数据库,其中Accountgroup
table将具有动态字段,以便Accounts
在需要时输入这些动态字段值.这可能并不重要,但我正在使用C#与EF和Linq.
这对我来说很难,因为我从来没有做过这样的事情,因为我做了我的研究,每个人都说EAV系统太可怕了,你应该设计得不同,问题是之后没有人告诉 - 怎么样?
所以也许你可以帮助我,告诉我如何在不做EAV的情况下实现类似的东西?
这就是我到目前为止所拥有的.
c# database database-design entity-framework entity-attribute-value
我想知道是否可以在嵌套文档上使用TTL.
我有Account
,我在里面Sessions
.Sessions
需要在30分钟后到期.我已经设置了所有内容但显然当我设置TTL索引时Account.Sessions.EndDateTime
它会删除整个Account
.我可以确保它只删除Session
吗?
这就是它在数据库中的样子.注意它将如何删除整个Account
而不仅仅是Session
什么时候EndDateTime
会发生.
{
"_id" : ObjectId("53af273888dba003f429540b"),
"Email" : "steve@s3te5ve.com",
"PasswordHash" : "CZaBEQRbwWNgJBjyhks7gH0Z3v5ZvDkW29pryF0DEXyE8rIw0NA4x39+uQneArKaUv97sP1e+e22YT1glbqQsw==",
"PasswordSalt" : "100000.Qx4D8uj7oDcWHRTLGRRTDwVkw2UcaM52XkDR9k2ga073Ow==",
"Sessions" : [
{
"Token" : "da55cf0783c4249b26283948fcae6caa15df320ca456203045aea81cad691df8",
"IpAddress" : "::1",
"StartDateTime" : ISODate("2014-06-28T20:36:27.000Z"),
"EndDateTime" : ISODate("2014-06-28T21:06:27.000Z")
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我创建索引的地方.
if (!_db.Accounts.IndexExists("Sessions.EndDateTime"))
{
_db.Accounts.CreateIndex(IndexKeys.Ascending("Sessions.EndDateTime"),
IndexOptions.SetTimeToLive(new TimeSpan(0)));
}
Run Code Online (Sandbox Code Playgroud) 当你运行dotnet run
你的MVC6应用程序时,第一次请求需要很长时间,但它显然工作正常.我试图在谷歌找到答案,但这是不可能的,因为我得到的是关于IIS的文章,我完全没有使用.实际上我在Ubuntu上运行代码.
有可能预热,dotnet run
所以第一个请求会像第二个请求一样快吗?