我使用MailKit从GMail帐户中读取一些消息.工作得很好,但是当我的应用程序读取了一条消息时,我想将消息标记为已读,并将该状态保存到GMail.MailKit可以实现吗?我还没有发现任何相关信息.
最好的问候René
我正在玩ASP.NET核心和.NET核心项目.对于经典的C#项目,Visual Studio 2015具有计算代码度量的功能.对于.NET Core,预览2工具中缺少支持.
在工具更完整之前,有没有人知道解决方法?
我正在尝试在登录成功时将身份验证密钥存储到我的cookie中:
HttpContext.Response.Cookies.Append("Bearer", accessToken, cookieMonsterOptions);
Run Code Online (Sandbox Code Playgroud)
所以在控制器类中这是有效的.我可以轻松创建和阅读我的cookie.但是现在我想检查一下,如果它存在,请读取我的cookie的值,_Layout.cshtml并显示登录用户的名称 - 或登录的链接.但是如何在部分中读取我的cookie _Layout.cshtml?
string value = HttpContext.Request.Cookies.Get("Bearer");
Run Code Online (Sandbox Code Playgroud)
不起作用.它试图添加System.Web到我的使用或者说HttpContext是静态的并且需要访问的引用Request.
有什么建议或想法吗?
我有以下过滤器属性,我可以像这样将字符串数组传递给属性[MyAttribute("string1", "string2")].
public class MyAttribute : TypeFilterAttribute
{
private readonly string[] _ids;
public MyAttribute(params string[] ids) : base(typeof(MyAttributeImpl))
{
_ids = ids;
}
private class MyAttributeImpl : IActionFilter
{
private readonly ILogger _logger;
public MyAttributeImpl(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<MyAttribute>();
}
public void OnActionExecuting(ActionExecutingContext context)
{
// HOW DO I ACCESS THE IDs VARIABLE HERE ???
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何将字符串数组传递_ids给动作过滤器的实现?我错过了一些非常明显的东西!?
c# custom-action-filter actionfilterattribute asp.net-core-mvc asp.net-core
这是我"学习"如何操作的页面:https://stormpath.com/blog/token-authentication-asp-net-core
但对我来说这不起作用(也不适用于Fiddler)我的ApplicationUser模型有这个控制器:
[Authorize] //works when it's not set, doesn't work when it's set
[Route("api/[controller]")]
public class ApplicationUserController : Controller
{
private IRepository<ApplicationUser> _applicationUserRepository;
public ApplicationUserController(IRepository<ApplicationUser> applicationUserRepository)
{
_applicationUserRepository = applicationUserRepository;
}
[HttpGet("{id}")]
public ApplicationUser Get(int id)
{
return _applicationUserRepository.Get(id);
}
}
Run Code Online (Sandbox Code Playgroud)
并且我的RestSharp包装器可以获取所有应用程序用户:
public Task<T> GetResponseContentAsync<T>(string resource, int id) where T : new()
{
RestRequest request = new RestRequest($"{resource}/{{id}}", Method.GET);
request.AddUrlSegment("id", id);
if (!AuthenticationToken.IsNullOrEmpty(true))
{
request.AddHeader("Authorization", string.Format("Bearer {0}", AuthenticationToken));
_client.Authenticator = new JwtAuthenticator(AuthenticationToken);
_client.Authenticator.Authenticate(_client, request);
}
TaskCompletionSource<T> tcs …Run Code Online (Sandbox Code Playgroud) 我想在ASP.NET Core应用程序中测量我的XUnit-Tests的代码覆盖率.Visual Studio 2015中的.NET Core工具是预览2,目前代码覆盖率不起作用.
2月份的博客文章http://dotnetthoughts.net/measuring-code-coverage-of-aspnet-core-applications-using-opencover/通过使用打开封面的命令行显示了一种解决方法.我正在寻找Visual Studio内部更加集成的方式.
有没有人听说过与XUnit结合使用的更好/更集成的代码覆盖率测量方法?
我正在使用Postman测试我的第一个.net Core WebAPI
发生未知的媒体类型错误.
我错过了什么?
这是我的发布对象
public class Country
{
[Key]
public int CountryID { get; set; }
public string CountryName { get; set; }
public string CountryShortName { get; set; }
public string Description { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是webapi控制器
[HttpPost]
public async Task<IActionResult> PostCountry([FromBody] Country country)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
_context.Country.Add(country);
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (CountryExists(country.CountryID))
{
return new StatusCodeResult(StatusCodes.Status409Conflict);
}
else
{
throw;
}
}
return CreatedAtAction("GetCountry", new { …Run Code Online (Sandbox Code Playgroud) 我有字符串:
<p justify;"="">Verslo centrai Lietuvos nekilnojamojo turto pl?tros asociacijos konkurse ...</p>
Run Code Online (Sandbox Code Playgroud)
并希望删除标签
<p justify;"=""></p>
Run Code Online (Sandbox Code Playgroud)
我的代码:
$content = strip_tags($text, '<p>');
Run Code Online (Sandbox Code Playgroud)
但我得到空字符串:string(0) "",我做错了什么?
我有一个包含文件路径的字符串列表.
List<string> allFilesWithPathList = new List<string>();
allFilesWithPathList.Add(@"G:\Test\A.sql");
allFilesWithPathList.Add(@"G:\Test\B.sql");
allFilesWithPathList.Add(@"G:\Test\C.sql");
return allFilesWithPathList;
Run Code Online (Sandbox Code Playgroud)
我有另一个列表,其中包含文件的子集 - 但它只有文件名; 不是路径.
List<string> excludeList = new List<string>();
excludeList.Add("B.sql");
Run Code Online (Sandbox Code Playgroud)
现在我需要从allFilesWithPathList获取excludeList中不存在的文件.目前,我EXCEPT在创建另一个仅包含文件名的列表后,正在执行以下操作.
List<string> allFileNamesOnlyList = new List<string>();
foreach (string fileNameWithPath in allFilesWithPathList)
{
//Remove path and get only file name
int pos = fileNameWithPath.LastIndexOf(@"\") + 1;
string value = fileNameWithPath.Substring(pos, fileNameWithPath.Length - pos);
allFileNamesOnlyList.Add(value);
}
//EXCEPT logic
List<string> eligibleListToProcess = allFileNamesOnlyList.Except(excludeList).ToList();
Run Code Online (Sandbox Code Playgroud)
在LINQ不引入上述其他列表的情况下,使这种逻辑工作的最佳方法是什么?
注意:我正在使用 .Net 4.5
完整的代码
class Program
{
static void Main(string[] args)
{
List<string> allFilesWithPathList …Run Code Online (Sandbox Code Playgroud)