asp.net-core-mvc

ModelState.IsValid is false prior to validation

怎甘沉沦 提交于 2019-12-31 06:58:40
问题 We wrote a custom model binder that overrides the CreateModel method of the ComplexTypeModelBinder so that we can have injection into our ViewModels instead of having to pass the injected clients and repos to our model from the controller . For example, for a model like this: public class ThingViewModel { public ThingViewModel (IThingRepo thingRepo) {} } In our controller we can do: public class ThingController : Controller { public IActionResult Index(ThingViewModel model) => View(model); }

CORS works for direct requests to API but not for static files (like css)

久未见 提交于 2019-12-31 03:18:06
问题 We are developing a project which is consisted of an Android Mobile App along with a Web API . The web API is Asp.net MVC Core. I have enabled the CORS service on my Startup.cs , hence Mobile app API calls are Cross Origin accessible and I receive access-control-allow-origin →* in the response headers. A part of the result that API returns to the mobile app request is HTML (to be shown as an ad in a mobile view) containing some CSS files. When the HTML is loaded in the Mobile View, CSS files

How to redirect after Azure AD authentication to different controller action in ASP Net Core MVC

孤人 提交于 2019-12-31 03:12:06
问题 I have setup my ASP Net Core 2.0 project to authenticate with Azure AD (using the standard Azure AD Identity Authentication template in VS2017 which uses OIDC). Everything is working fine and the app returns to the base url (/) and runs the HomeController.Index action after authentication is successful. However I now want to redirect to a different controller action (AccountController.CheckSignIn) after authentication so that I can check if the user already exists in my local database table

What is an analog of request.Properties in ASP.NET 5

≯℡__Kan透↙ 提交于 2019-12-30 23:48:34
问题 In WebApi2 it was common to put arbitrary objects into HttRequestMessage.Properties . Usually it was doing with extension-methods like request.SetUserRights() where SetUserRights just put an object into request.Properties[HttpPropertyKey.UserRights] . Now in ASP.NET 5 there is no such property in HttpRequest . What pattern is supposed to be be used for passing arbitrary objects along with http request? In WebApi for putting objects in request.Properties filters were used usually. We still

How can I bind an array with asp-for tag?

依然范特西╮ 提交于 2019-12-30 18:33:47
问题 I would like to ask, how can I bind an array in Asp.NET Core MVC ? <input type="text" asp-for="Requests[@index].Name" /> It was working very well in older versions of ASP MVC. This example shows "Internal server error". " An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately. " ViewModel class example: public class ViewModel { public List<Model> Requests {get;set;} }

Create RSS feed in asp.net core 1.0

会有一股神秘感。 提交于 2019-12-30 10:56:53
问题 I am working in Asp.net Core 1.0 MVC 6 I am trying to write a component to provide RSS feeds from my websites. I found this post that suggests that System.ServiceModel.Syndication has yet to be ported to ASP.NET CORE. I am unable to target the full .NET framework. The suggestion is to write as an xml parser. I am however struggling to get my head around everything that might be required. I have built the functionality to get my data into XML but now need to better understand how to allow this

ASP.Net core MVC6 Redirect to Login when not authorised

自作多情 提交于 2019-12-30 10:48:34
问题 I am using ASP.Net core MVC 6, I am trying to get the user redirected to the login page if they are not authenticated. I cant seem to get it to work, currently the user just gets a blank page. Below is my ConfigureServices method in Startup.cs public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")) ); services.AddIdentity

Sharing Cookies Between Two ASP.NET Core Applications

风流意气都作罢 提交于 2019-12-30 06:58:20
问题 I'm using WsFederation in two separate ASP.NET Core projects. Each project has the following in Startup.cs services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = WsFederationDefaults.AuthenticationScheme; }) .AddWsFederation(options => { options.Wtrealm = Configuration["Wtrealm"]; options

What's the alternative to DataTable with ADO.NET under MVC 6?

折月煮酒 提交于 2019-12-30 06:42:08
问题 I am creating a MVC 6 project and I would rather use Classic ADO.net over Entity Framework 7. However It is saying that name space can not be found for both DataTable and SqlDataAdapter . I have a using System.Data and System.Data.SqlClient statement. It dose not show an error until I try to build the project. I think I read somewhere that those two names spaces are not implemented in the new version. If so is there an alternative way of doing it or am I missing a dependency or using

.net core identity 2.1 role authorize not working

时间秒杀一切 提交于 2019-12-30 06:08:41
问题 I've implemented role based auth several times pre 2.1. Followed the steps to scaffold the new 2.1 identities. I extended the IdentityUser model to add additional fields, login works fine, new fields are present. startup.cs configure services contains services.AddDefaultIdentity<AppUser>() .AddRoles<IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>(); I seeded the roles IdentityRole role = new IdentityRole(); role.Name = "Administrator"; IdentityResult roleResult = roleManager.