我正在使用命名空间System.Runtime.Remoting.Proxies
和System.Runtime.Remoting.Messaging
C#中的AOP.我正在尝试将我的应用程序从.Net Framework 4.6移植到dnxcore/dotnet核心.
Intellisense说,这两个命名空间不适用于我的framework-vesion(netcoreapp1.0/dnxcore50).知道这两个命名空间是否会出现?或者任何想法如何使用RealProxy
-class 获得AOP ?
我不想使用第三方库 - 我只想使用.Net提供给我的东西.
我正在尝试在登录成功时将身份验证密钥存储到我的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
.
有什么建议或想法吗?
我在某些应用程序中有这种代码(来自microsoft)
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Naming",
"CA1702:CompoundWordsShouldBeCasedCorrectly",
MessageId = "CounterClockwise",
Scope = "member",
Target = "ScePhotoViewer.PhotoDisplayControl.#RotatePhotoCounterClockwiseCommand"
)]
Run Code Online (Sandbox Code Playgroud)
谢谢乔纳森
这是我"学习"如何操作的页面: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) 我对Entity Framework的性能提出了一些疑问.
就像是
using (MyContext context = new MyContext())
{
Document DocObject = context.Document.Find(_id);
int GroupCount = context.Document.Where(w=>w.Group == DocObject.Group).ToList().Count();
}
Run Code Online (Sandbox Code Playgroud)
我的数据库大约需要2秒钟(大约30k数据集),而这一个
using (MyContext context = new MyContext())
{
Document DocObject = context.Document.Find(_id);
int GroupCount = context.Document.Where(w=>w.Group == DocObject.Group).Count();
}
Run Code Online (Sandbox Code Playgroud)
需要0.02秒.
当我的10个文档的过滤器有20秒等待时,我检查了我的代码,并将其更改为ToList()
以前不使用Count()
.
任何想法为什么这条线需要2秒ToList()
?
我终于通过JWT令牌认证工作获得了登录方法.
我在这里打电话
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
ClaimsPrincipalFactory.CreatePrincipal(claims),
authProps);
Run Code Online (Sandbox Code Playgroud)
我也打过电话
await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
Run Code Online (Sandbox Code Playgroud)
在示例中,我读到我只需要SignInAsync
.所以我测试了它并删除了AuthenticateAsync
.但是,User.Identity.IsAuthenticated
回归true
.
可以删除AuthenticateAsync
吗?还是我还需要它?它为什么存在?文档字符串AuthenticateAsync
只表示验证的扩展方法
客户向我发送了一个字体,其中未定义'...'字符(它只显示镜像反转'3').所以我想做一些像:
.myclass ul li{
text-overflow: ellipsis;
text-overflow-content: '...';
}
Run Code Online (Sandbox Code Playgroud)
任何想法,我怎么能这样做?
我的应用程序有一个API部分和一个网站部分.在网站上,用户可以登录并从API获取JWT承载令牌.
我现在的问题是:
我应该在哪里存储该令牌?
有人说,将它存储在Cookie中(而其他人说"不要,因为CSRF"),有人说HTML5 Web存储,有人说使用Session(而其他人说,"不要在ASP Net Core中使用Sessions")和我看到一篇文章,其中某人将auth-token存储在数据库中(??).那么,现在正确的地方是什么?
我在使用.net core 2.0运行的Web-API中实现了JWT Bearer Token-Authentication.现在我创建了另一个与我的Web-API对话的网站.检索令牌有效,我将其添加到cookie中,当我调试时,我可以看到我的cookie(名称是"identity")具有正确的值.
在项目模板中,有一个HomeController
带有操作的控制器.我正在使用该操作Contact
用于我的目的并使用以下内容对其进行注释AuthorizeAttribute
:
[Authorize]
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";
return View();
}
Run Code Online (Sandbox Code Playgroud)
现在我正在浏览(作为匿名用户)/home/contact
- 完美:它将我重定向到/home/login
我需要登录的位置.
当我尝试登录时,我收到以下错误消息:
没有IAuthenticationSignInHandler配置为处理该方案的登录:承载
我猜令牌配置是错误的 - 我想还有一些我在这里做错的事情.
首先,这是我的Startup.cs(由于订单依赖,我没有删除任何内容):
public void ConfigureServices(IServiceCollection services)
{
services.AddDistributedMemoryCache();
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
});
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("mysupersecret_secretkey!123")),
ValidateIssuer …
Run Code Online (Sandbox Code Playgroud) 我知道在构造函数中有很多关于虚拟成员调用的问题(在将其标记为重复之前).我已经明白了,为什么会出现问题.
对我来说还有两个未解答的问题:
实体框架6希望我将外键集合设置为虚拟.但是,我想在某处初始化它们以防止它们NullReferenceExceptions
.
关于教程示例:
public class Student
{
public Student() { }
public int StudentId { get; set; }
public string StudentName { get; set; }
public virtual Standard Standard { get; set; }
}
public class Standard
{
public Standard()
{
Students = new List<Student>();
}
public int StandardId { get; set; }
public string Description { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
他们肯定希望我ICollection<Student>
在构造函数中初始化虚拟.我从关于这个主题的其他问答中理解的是,这只是关于继承.当我的类没有继承时,这没关系(不好,但还可以).
(ReSharper建议,让我的课程密封.但是,eeehm,是的,我不能拥有虚拟成员,实体框架想拥有?所以这不是真的有用.)所以现在,我会留在构造函数赋值.
关于C#6 …
c# ×8
asp.net-core ×5
access-token ×2
.net-core ×1
aop ×1
asp.net ×1
asp.net-mvc ×1
bearer-token ×1
c#-6.0 ×1
constructor ×1
cookies ×1
css ×1
dnx ×1
html ×1
jwt ×1
performance ×1
restsharp ×1
tfs ×1
wpf ×1