asp.net-core-mvc

Not able to use XUnit for unit tests in ASP.NET VNext and Visual Studio 2015 RC

妖精的绣舞 提交于 2020-01-02 16:08:21
问题 I created a a Visual Studio 2015 RC solution as follows: Project global.json Source MvcProject MvcProject.Test MvcProject.Test is a class library where I created a Test. The global.json file has the following: { "projects": [ "Source" ], "sdk": { "version": "1.0.0-beta4" } } And project.json in MvcProject.Test is: { "compilationOptions": { "warningsAsErrors": true }, "dependencies": { "Microsoft.AspNet.Mvc": "6.0.0-*", "xunit.runner.aspnet": "2.0.0-aspnet-*" }, "commands": { "test": "xunit

Hooking into razor page execution for ASP.Net Core

白昼怎懂夜的黑 提交于 2020-01-02 10:04:11
问题 I'm trying to hook into the ExecuteAsync() call that renders a razor page using my CUSTOM view page (that inherits from RazorPage ). In the RazorPage class there is this abstract method: public abstract Task ExecuteAsync(); That method gets called within the output generated by razor when parsing a .cshtml file (view). Obviously, I cannot just override it because mine would never get called from the view that gets generated, which also overrides this method (though that would be nice, and

PagedList.Core.Mvc PagedListPager Html extension in .Net Core is not there

天大地大妈咪最大 提交于 2020-01-02 06:49:33
问题 It seems like the PagedList.Core does not contain the extension method for Html helper, so I cannot use the code below: @Html.PagedListPager(Model, page => Url.Action("Index", new { page }), PagedListRenderOptions.MinimalWithItemCountText) I was able to successfully implement the paging in previous version of MVC, but it does not work in ASP.Net Core. Below I have attached IL Dasm reference. Am I missing something, or is there any other way to implement that? PagedList.Mvc: PagedList.Core.Mvc

asp.net mvc core how can I return a Json query

笑着哭i 提交于 2020-01-02 05:53:57
问题 First and foremost I Know how to return a Json Query by doing this public JsonResult streams() { using (var conn = new NpgsqlConnection(Connectionstring)) { conn.Open(); var credentials = conn.Query<Streams>("select id,name from streams").ToList(); ViewData["Message"] = "Your application description page."; conn.Close(); return Json(credentials); } } That code above returns Json for me from the database, however now I am actually returning the Json from the SQL code by changing the query to

asp.net mvc core how can I return a Json query

给你一囗甜甜゛ 提交于 2020-01-02 05:53:21
问题 First and foremost I Know how to return a Json Query by doing this public JsonResult streams() { using (var conn = new NpgsqlConnection(Connectionstring)) { conn.Open(); var credentials = conn.Query<Streams>("select id,name from streams").ToList(); ViewData["Message"] = "Your application description page."; conn.Close(); return Json(credentials); } } That code above returns Json for me from the database, however now I am actually returning the Json from the SQL code by changing the query to

How do you initialize application state at startup and access it from controllers in MVC 6?

删除回忆录丶 提交于 2020-01-02 05:34:11
问题 Let's say I have a class called MySiteConfiguration in which I have a bunch of, you guessed it, configuration data. This data will not change over the course of the application's runtime after it has been loaded. My goal would be to construct an instance of this class at startup and access it from my controller actions. I do not want to construct the class more than once, as this should not be needed. To do this in WebApi 2 for instance, I would: Instantiate the class in my application start

Using WebGrid in ASP.NET Core

别来无恙 提交于 2020-01-02 05:30:31
问题 I am using System.Web.Helpers.WebGrid control in ASP.NET Core application, I am getting the below error while rendering the grid An unhandled exception occurred while processing the request. ArgumentNullException: Value cannot be null. Parameter name: httpContext System.Web.HttpContextWrapper..ctor(HttpContext httpContext) at line System.Web.Helpers.WebGrid objWebGrid = new System.Web.Helpers.WebGrid(Model.MeetingsObj); Model: public class Meeting { public int MeetingId { get; set; } public

Bad Request - Invalid Hostname when accessing localhost Web API or Web App from across LAN

谁都会走 提交于 2020-01-02 03:28:27
问题 I have an ASP .Net Core 1.1 Web API and Web App running on my localhost from Visual Studio 2017 on Windows 10. When I run the projects, the API runs on http://localhost:50082/api/ and the web app on http://localhost:60856/ However, if others on the LAN try to access it (using my computer's IP address - http://192.168.1.101:60856/ they get a Bad Request - Invalid Hostname Error. In fact,. I get this error too of I use my IP address. I've tried about a dozen variations in my C:\Users\Documents

User.GetUserId() fails inside controller's constructor

谁说胖子不能爱 提交于 2020-01-02 03:17:56
问题 I am getting the following error: Value cannot be null. Parameter name: principal How can I access Identity (userId) inside the controller's constructor? I can only get it working by wrapping the failed call in a function (both highlighted below). Is there anything I need to inject? public class BaseController : Controller { protected readonly MylDbContext dbContext; protected readonly string userId; public BaseController(MylDbContext dbContext) { this.dbContext = dbContext; userId = User

Identity Server 4/nativescript Hangs

吃可爱长大的小学妹 提交于 2020-01-02 01:57:47
问题 I have the following client: new Client { ClientId = "nativeapptest", ClientName = "Native App Test", Enabled = true, RequireClientSecret = false, AllowedGrantTypes = GrantTypes.Code, RedirectUris = { "com.mysite.nativeapp.12365789785256-buv2dwer7jjjjv5fckasdftn367psbrlb:/home" }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "MyScope" }, RequirePkce = false, AllowOfflineAccess = true, RequireConsent = false } I am using