asp.net-core-mvc

.net core identity 2.1 role authorize not working

好久不见. 提交于 2019-12-30 06:08:27
问题 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.

How to get user id of logged in user in .NET Core 2.0?

我的梦境 提交于 2019-12-30 05:01:08
问题 I have created a angular 2 application using .NET Core and MVC. I want to know the login id of user. How to get logged in id of a user in .net core? This is my first angular application. I used following link to start https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/ I want to use windows authentication, to get login id in a controller. 回答1: That really depends on what kind of authentication you have in your app.

MVC 6 Routing, SPA fallback + 404 Error Page

随声附和 提交于 2019-12-30 04:38:04
问题 With RC1 of ASP.NET Core 1.0's MVC 6 you can map routes from within your Startup.Configure function when invoking app.UseMvc . I have mapped a "spa-fallback" route that will ensure that the HomeController and Index view are the defaults like so: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // ... omitted for brevity app.UseExceptionHandler("/Home/Error"); app.UseStatusCodePagesWithRedirects("/Home/Error/{0}"); app.UseMvc(routes => {

Getting autofac to work with mvc6 beta5

拜拜、爱过 提交于 2019-12-30 04:34:09
问题 I am trying to get autofac working with an mvc6 application I am working on. I found this blog article however it seems to be a little dated. It looks like its using the beta3 bits I am using this clr version 1.0.0-beta5-11911 My project has these 2 references "Autofac": "4.0.0-alpha2", "Autofac.Dnx": "4.0.0-alpha2", Within the article is talks about how to modify the startup.cs // Create the Autofac container builder. var builder = new Autofac.ContainerBuilder(); // Add any Autofac modules

User.Identity.IsAuthenticated always false in .net core custom authentication

情到浓时终转凉″ 提交于 2019-12-30 04:28:05
问题 Can anyone please check below code and let me know why I'm getting always false (User.Identity.IsAuthenticated)??. I'm getting cookie on my browser properly and able to get value from Claim but "User.Identity.IsAuthenticated" always false. public async Task<IActionResult> Login(string phoneNumber, int otp, string returnUrl) { if (this.accountService.ValidateOTP(phoneNumber, otp)) { var claims = new List<Claim> { new Claim(ClaimTypes.MobilePhone, phoneNumber), new Claim(ClaimTypes.Name,

Can I use a Tag Helper in a custom Tag Helper that returns html?

社会主义新天地 提交于 2019-12-30 03:46:04
问题 I recently ran into a situation where I would like to use a tag helper within a tag helper. I looked around and couldn't find anyone else trying to do this, am I using a poor convention or am I missing documentation? Ex. Tag Helper A outputs HTML that contains another tag helper. Ex. [HtmlTargetElement("tag-name")] public class RazorTagHelper : TagHelper { public override void Process(TagHelperContext context, TagHelperOutput output) { StringBuilder sb = new StringBuilder(); sb.Append("<a asp

How can I wrap Web API responses(in .net core) for consistency?

帅比萌擦擦* 提交于 2019-12-30 01:51:05
问题 I need to return a consistent response with a similar structure returned for all requests. In the previous .NET web api, I was able to achieve this using DelegatingHandler (MessageHandlers). The object that I want to return will be encapsulated in the Result element. So basically the json response will be in this kind of structure: Example 1: { "RequestId":"some-guid-abcd-1234", "StatusCode":200, "Result": { "Id":42, "Todo":"Do Hello World" } } Example 2: { "RequestId":"some-guid-abcd-1235",

DbContext for background tasks via Dependency Injection

老子叫甜甜 提交于 2019-12-29 18:42:52
问题 I am probably not thinking in the right direction. I am fairly new to Dependency Injection and ASP.Net Core. I have a ASP.Net core website, and one of the tasks is to import data from an excel sheet to a database that a user will upload. The excel sheets can be huge and the data transformation tasks are time taking, hence I wish to perform them in the background. i.e. The user will upload the sheet, the response will be sent immediately and the background job/thread will import the data. I am

Data loss when passing raw HTML from View to Controller in POST request — XSS-safety & information loss

不羁岁月 提交于 2019-12-29 09:36:13
问题 Preamble My use-case includes a front-end WYSIWYG editor. Taking user input in HTML5/CSS format from the CSHTML Front-End View. Receiving the input in the Backend Controller's action via POST request. And finally doing fancy Database stuff with it. Sounds pretty easy. Using this beast of an editor, it's very straightforward and customizable. View WYSIWYG editor textarea nested within a form to send editor's raw HTML data using POST <form class="form" asp-controller="CreationController" asp

Access to Configuration object from Startup class

白昼怎懂夜的黑 提交于 2019-12-29 08:41:28
问题 I would like to access to the Active Directory from my company in many controllers from my ASP.NET vNext project, and I inserted the domain name into my config.json file, so I can access it from the Configuration class. I find it heavy to always instantiate a new Configuration object at every time I want to access to my config.json, is there any way through the IConfiguration API to access to the Configuration class initialized into the Startup class ? 回答1: An example of how you can do this: