Tag: asp.net core

HttpRuntime.Cache等效于asp.net 5,MVC 6

所以我刚刚从ASP.Net 4迁移到ASP.Net 5.我现在正试图改变一个项目,以便它在新的ASP.Net中运行,但当然会出现一大堆错误。 有谁知道HttpRuntime的等效扩展是什么,因为我似乎无法在任何地方找到它。 我正在使用缓存对象客户端。 HttpRuntime.Cache[Findqs.QuestionSetName] ‘Findqs’只是一个普通的对象

在.NET Core 1.1 csproj中引用.NET 4.5 dll?

我正在运行VS 2017 RC4。 我将.NET Core应用程序中的引用添加到我的.NET 4.5 dll中并进行编译。 当在运行时调用引用dll的行时,我得到: System.IO.FileNotFoundException: ‘Could not load file or assembly ‘System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′. The system cannot find the file specified.’ 此图显示要使用4.5引用,我需要使用netstandard 1.1。 http://sofzh.miximages.com/c%23/172.png 假设这是我需要的,我如何在我的.csproj中引用它? 我只能在使用project.json时找到旧文档。 我尝试添加以下但它没有帮助: 1.1 另外,我需要添加: 1.0.3 或者我得到FileNotFoundException:无法加载文件或程序集。 该系统找不到指定的文件。 这是为什么? 以下是我的.csproj的相关部分: netcoreapp1.1 $(PackageTargetFallback);portable-net45+win8+wp8+wpa81; 1.0.3 Dlls\My4.5dll.dll

实体类型上的导航尚未添加到模型中,或被忽略,或者实体类型被忽略

实体类型“Notepad.Models.Note”上的导航“标签”尚未添加到模型中,或被忽略,或者实体类型被忽略。 public class Note { public Note() { CreationDate = DateTime.Now; Tags = new HashSet(); Parts = new HashSet(); } public int ID { get; set; } public virtual ICollection Tags { get; set; } public virtual ICollection Parts { get; set; } public DateTime? CreationDate { get; set; } } public class Tag { […]

虽然存在依赖关系和使用,但找不到类型或命名空间名称“Ping”

我正在创建一个程序来ping网络中的计算机。 为此,我试图使用类ping,来自 namespace System.Net.NetworkInformation.Ping 我正在使用ASP.NET 5.0所以我hava project.json文件与我的dependecies { “version”: “1.0.0-*”, “dependencies”: { “NetworkSniffer”: “1.0.0-*”, “Microsoft.AspNet.Mvc”: “6.0.0.0-beta2” }, “commands”: { “run”: “run” }, “frameworks”: { “aspnet50”: { “dependencies”: { “System.Console”: “4.0.0-beta-22231”, “System.Net.NetworkInformation”: “4.0.10-beta-22231” } }, “aspnetcore50”: { “dependencies”: { “System.Console”: “4.0.0-beta-22231”, “System.Net.NetworkInformation”: “4.0.10-beta-22231” } } } } 一个简单版本的控制台代码仍然给出错误: using System.Net.NetworkInformation; namespace TestApp { public class Program […]

EF。 连接没有关闭。 连接的当前状态是连接

我有jwt auth: var messageHandlers = new JwtMessageHandler(_serviceProvider); app.UseJwtBearerAuthentication(new JwtBearerOptions { AutomaticAuthenticate = true, AutomaticChallenge = true, Events = new JwtBearerEvents { OnMessageReceived = messageHandlers.OnMessageReceived, }, TokenValidationParameters = tokenValidationParameters }); JwtMessageHandler是我的自定义处理程序。 在处理程序中,我必须对数据库进行一些查询,因此我传递ServiceProvider并解析我的用户服务: public class JwtMessageHandler { private IUserService _userService; public async Task OnMessageReceived(MessageReceivedContext arg) { //parsing header, get claims from token … _userService = (IUserService)arg.HttpContext.RequestServices.GetService(typeof(IUserService)); var […]

获取所有路线的列表

在ASP.NET Core中,有没有办法查看Startup中定义的所有路由的列表? 我们使用IRouteBuilder的MapRoute扩展方法来定义路由。 我们正在迁移旧的项目WebAPI项目。 我们可以使用GlobalConfiguration.Configuration.Routes来获取所有路由。 更具体地说,我们在动作filter中执行此操作。 public class MyFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext actionContext) { base.OnActionExecuting(actionContext); // This no longer works // var allRoutes = GlobalConfiguration.Configuration.Routes; // var allRoutes = ??? } }

在没有IOptions 的情况下从appsettings.json读取和使用设置?

.NET Core 允许从配置文件中懒惰地读取设置,将其反序列化为POCO并使用一行代码在内置DI容器中注册该POCO: public void ConfigureServices(IServiceCollection services) { services.Configure(Configuration.GetSection(“MySection”)); } 然后任何消费者都可以解析IOptions来访问该POCO: public HomeController(IOptions optionsAccessor) { MyOptions options = optionsAccessor.Value; } 这种方法有明显的缺点: Microsoft.Extensions.Options包中不必要的依赖项: 模拟,测试和显式实例创建变得更加冗长。 在没有IOptions情况下解决选项最简单的解决方案是什么?

在visual studio 2015下以x86启动asp.net核心项目

我有一个包含asp.net核心项目的vs2015解决方案,并将其project.json配置如下: { “buildOptions”: { “emitEntryPoint”: true, “preserveCompilationContext”: true, “platform”: “x86” }, “runtimes”: { “win10-x86”: {} }, “frameworks”: { “net461”: {} }, “commands”: { “web”: “Microsoft.AspNet.Hosting –ASPNET_ENV production –server Microsoft.AspNet.Server.Kestrel –server.urls http://+:12345”, } […] } 我期待应用程序使用project.json中指定的平台构建和运行(仅供参考,我在win10 / x64盒子上通过vs2015调试器运行应用程序) 。 但是,使用win7-x64运行时。 我可以看到一个win7-x64输出目录,启动的提示标题也表明它。 如果我通过指定运行时的命令行直接构建和运行,它就可以工作。 所以我的问题是,我需要配置什么来从vs2015启动x86中的asp.net核心应用程序?

如何自定义实现asp.net身份的UpdateAsync方法?

我正在做自定义asp.net身份而不使用asp.net内置表。我已成功创建用户实现自定义CreateAsync 现在我想用新的加密密码更新用户,所以我没有得到如何提供UpdateAsync method自定义实现。 这是我的表: 用户 : Id,Name,EmailId,Password,Statistics,Salary 型号 : public class UserModel : IUser { public string Id { get; set; } public string Name { get; set; } public string EmailId { get; set; } public string Password { get; set; } public int Salary { get; set; } } 我实现IUserstore的自定义类: public class UserStore […]

如何在asp.net核心中编写自定义actionResult

在webApi2中,我可以通过inheritanceIHttpActionResult来编写自定义ActionResult。 样品: public class MenivaActionResult : IHttpActionResult { private readonly HttpRequestMessage _request; private readonly ServiceResponseBase _response; public MenivaActionResult(HttpRequestMessage request, ServiceResponseBase response) { _request = request; _response = response; } public Task ExecuteAsync(CancellationToken token) { HttpResponseMessage httpresponseMessage = _response.Exception != null ? _request.CreateErrorResponse((HttpStatusCode)_response.HttpCode, _response.Exception.Message+”:”+_response.Exception.HelpCode) : _request.CreateResponse((HttpStatusCode)_response.HttpCode, _response.Data); return Task.FromResult(httpresponseMessage); } } ServiceResponseBase类对象包含服务层的所有exception和数据。 我如何将此代码移植到asp.net核心。 我试过,但我不知道如何从.net核心中的HttpRequestMessage对象创建响应消息。 IActionResult只有Task ExecuteResultAsync(ActionContext […]