在Windows Phone 8中我有方法public async Task<bool> authentication()
.函数的返回类型是bool
但当我尝试在if
条件错误中使用其返回值时表示无法转换Task<bool>
为bool
.
public async Task<bool> authentication()
{
var pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string> ("user", _username),
new KeyValuePair<string, string> ("password", _password)
};
var serverData = serverConnection.connect("login.php", pairs);
RootObject json = JsonConvert.DeserializeObject<RootObject>(await serverData);
if (json.logined != "false")
{
_firsname = json.data.firsname;
_lastname = json.data.lastname;
_id = json.data.id;
_phone = json.data.phone;
_ProfilePic = json.data.profilePic;
_thumbnail = json.data.thumbnail;
_email = json.data.email;
return true;
}
else
return …
Run Code Online (Sandbox Code Playgroud) 我的Visual Studio安装有问题.
为了重现它,我创建了一个新的空白解决方案然后:
Visual Studio无法创建它我收到此消息:
元素<Project>下的元素<#text>无法识别.
任何想法如何解决?
我读到new
modifer隐藏了基类方法.
using System;
class A
{
public void Y()
{
Console.WriteLine("A.Y");
}
}
class B : A
{
public new void Y()
{
// This method HIDES A.Y.
// It is only called through the B type reference.
Console.WriteLine("B.Y");
}
}
class Program
{
static void Main()
{
A ref1 = new A(); // Different new
A ref2 = new B(); // Polymorpishm
B ref3 = new B();
ref1.Y();
ref2.Y(); //Produces A.Y line #xx
ref3.Y();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么 …
我遇到了Entity Framework的奇怪行为.EF生成的DbContext
对象返回与数据库中的实际数据不同的数据.
请考虑以下数据库架构:
Letter
数据:
Id Value LanguageId
------- ------- ----------
1 A 1
2 A 2
3 B 1
4 B 2
Run Code Online (Sandbox Code Playgroud)
Language
数据:
Id Value
------- -------
1 English
2 Russian
Run Code Online (Sandbox Code Playgroud)
我也有以下简单的观点LetterLanguageView
.请注意,它使用LEFT JOIN
子句,因为Letter.LanguageId
可能是NULL
:
SELECT dbo.Letter.Value as Letter, dbo.Language.Value as Language
FROM dbo.Letter
LEFT JOIN dbo.Language ON dbo.Letter.LanguageId = dbo.Language.Id
Run Code Online (Sandbox Code Playgroud)
这个视图的结果非常简单:
Letter Language
------- --------
A English
A Russian
B English
B Russian
Run Code Online (Sandbox Code Playgroud)
但是,当我从Entity Framework使用此视图时,我得到以下结果:
如您所见,该Language
物业是错误的,根本没有俄语.
如果您想知道,这是用于读取此数据的代码段: …
我正在向ASP.NET MVC 5 Web应用程序添加ASP.NET身份验证功能.
我在整个项目中使用Unity进行依赖注入,所以我决定注入AccountController
构造函数中所需的依赖项:
public AccountController(UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser, string> signInManager)
{
_userManager = userManager;
_signInManager = signInManager;
}
Run Code Online (Sandbox Code Playgroud)
我的Login
方法实现如下(实际上,我从ASP.NET Web Application
具有Individual User Accounts
身份验证的项目模板中复制了该代码):
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
// Process result and return appropriate view...
// However, there are no authentication cookies in the response!
}
Run Code Online (Sandbox Code Playgroud)
问题是,认证工作不正常-即使我进入了正确的凭据,result
是SignInStatus.Success
有在响应不发送身份验证cookie.
但是,如果我使用 …
我想知道使用这两个世界的优点和缺点:
我们专注于SPA/Mini-SPA,适用于具有大量服务器端业务规则和计算的中型/大型企业项目.我也专注于安全性.
优点和缺点意见将帮助我在脑海中找到这个问题的依据:
将ASP.NET Web API(后端),ASP.NET MVC和Angularjs一起使用是一个明智的决定吗?
c# asp.net-mvc asp.net-web-api angularjs single-page-application
我想实现的标准Id
中AspNetUsers
,从nvarchar
到int
.我已经设法让那一方工作了.但是我的问题是当我尝试登录时,我不断从UserManager
课堂上收到错误.
我的代码如下:
public class UserManager : UserManager<ApplicationUser, int>
{
public UserManager(IUserStore<ApplicationUser, int> store)
: base(store)
{
}
Run Code Online (Sandbox Code Playgroud)
在我登录的页面上
if (IsValid)
{
// Validate the user password
var manager = Context.GetOwinContext().GetUserManager<UserManager>();
var user = manager.Find(UserName.Text, Password.Text); //This line throws the error
if (user != null)
{
IdentityHelper.SignIn(manager, user, isPersistent: false);
Response.Redirect("~/Home.aspx"); }
else
{
FailureText.Text = "Invalid username or password.";
ErrorMessage.Visible = true;
}
}
Run Code Online (Sandbox Code Playgroud)
我一直得到的错误是System.ArgumentNullException:Value不能为null.参数名称:manager.还有其他人遇到过这个问题吗?在此先感谢您的帮助
堆栈跟踪
[ArgumentNullException: Value …
Run Code Online (Sandbox Code Playgroud) 背景
我们的应用程序发送在数据库表中排队的电子邮件.我们发送了一些重复电子邮件的实例,所以我实现了一个锁,以防止多个线程同时发送电子邮件.
ReSharper警告我:
该字段有时在同步块内使用,有时在没有同步的情况下使用
题
为什么ReSharper告诉我这个,为什么我会担心它?
码
这是我的(删节)代码:
private readonly IMailQueueRepository _mailQueueRepository = new MailQueueRepository();
private static object _messageQueueLock = new object();
public void SendAllQueuedMessages(IPrincipal caller)
{
lock (_messageQueueLock) // Prevent concurrent callers
{
var message = _mailQueueRepository.GetUnsentMessage();
while (message != null)
{
SendQueuedMessage(message);
message = _mailQueueRepository.GetUnsentMessage();
}
}
}
public void SendQueuedMessage(IMessage message)
{
// I get the ReSharper warning here on _mailQueueRepository
var messageAttachments = _mailQueueRepository.GetMessageAttachments(message.Id);
// etc.
}
Run Code Online (Sandbox Code Playgroud) 在.NET中Stack
,Queue
和和List
(以及它们的通用实现)在内部使用数组保存项目。
添加新元素时,内部数组的大小将增加一倍Push()
,Enqueue()
或者Add()
如果已满。
问题是,为什么在删除项目时这些数据结构不将内部数组减半?最好将上的阵列大小减半,或者如果阵列的大小小于四分之一,以防止浪费内存。Pop()
Dequeue()
Remove()
我使用以下代码检查此行为:
var s = new Stack<int>();
for (int i = 0; i <= 512; i++) s.Push(i); // Increases the array capacity to 1024.
for (int i = 0; i <= 512; i++) s.Pop(); // Doesn't decrease array capacity.
// Stack is empty, but internal array capacity is still 1024:
var fieldInfo = typeof(Stack<int>).GetField("_array", BindingFlags.NonPublic | BindingFlags.Instance); …
Run Code Online (Sandbox Code Playgroud) 我正在使用ASP.NET Webforms项目并使用Unity for DI.该项目还使用DevExpress ASP.NET Ajax控件.
现在我们遇到了问题,似乎是DevExpress和Unity之间的冲突.
这是Unity配置
[assembly: WebActivator.PostApplicationStartMethod(typeof(Sales.Web.App_Start.UnityWebFormsStart), "PostStart")]
namespace Sales.Web.App_Start
{
/// <summary>
/// Startup class for the Unity.WebForms NuGet package.
/// </summary>
internal static class UnityWebFormsStart
{
/// <summary>
/// Initializes the unity container when the application starts up.
/// </summary>
/// <remarks>
/// Do not edit this method. Perform any modifications in the
/// <see cref="RegisterDependencies" /> method.
/// </remarks>
internal static void PostStart()
{
IUnityContainer container = new UnityContainer();
HttpContext.Current.Application.SetContainer(container);
RegisterDependencies(container);
}
/// <summary> …
Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×4
asp.net ×2
asp.net-mvc ×2
owin ×2
angularjs ×1
arrays ×1
async-await ×1
c#-5.0 ×1
collections ×1
new-operator ×1
oop ×1
polymorphism ×1
resharper ×1
sql ×1