asp.net-core-mvc

using aspnet identity with custom tables

我的未来我决定 提交于 2019-12-06 02:57:48
I am working on asp.net MVC core application. I have custom database with users and roles tables. I want to use asp.net identity with custom tables so that I don't have to use aspnetusers, aspnet roles tables. How to do it with asp.net identity and asp.net core Good luck with that! :) I have just gone through that process last few days. I've got it to work but its really painful at some stages. In short: You need to create your own user model that implements IUser interface. You need to create your own DAL that gets data from your custom db tables You need to implement your own UserStore that

How to change/create custom FileProvider in .NET Core that's domain dependant (i.e. one web app serving multiple site rendering logics)

一世执手 提交于 2019-12-06 02:52:18
问题 I'm currently creating a multi-tenant web app using .NET Core. And is facing a problem: 1) The Web App serves different views and logics based on a set of domain names . 2) The views are MVC views and stored in Azure Blob Storage 3) The multiples sites share the same .NET Core MVC controllers therefore only the Razor views are different with small logics. Questions.... A) Is that possible? I created a MiddleWare to manipulate however I couldn't assign FileProviders on context level properly

ASP.NET Core serving a file outside of the project directory

大兔子大兔子 提交于 2019-12-06 02:44:40
问题 In my ASP.NET Core project I am trying to serve an html file like this: public IActionResult Index() { return File("c:/path/to/index.html", "text/html"); } This results in an Error: FileNotFoundException: Could not find file: c:/path/to/index.html Pasting the path from the ErrorMessage into my browser I am able to open the file, so the file is clearly there. The only way I have been able to serve the file is placing it in wwwroot in the project folder and serving it like this: public

ASP Net Core - Mixing External Identity Provider with Individual User Accounts for Audit Tracking

China☆狼群 提交于 2019-12-06 01:54:32
I have created a default ASP Net Core MVC web app with Individual User Accounts. I added a custom UserID INT field to the AspNetUsers table and linked this as a foreign key to all my other custom tables so I can track what users inserted/updated records in my database. I did this as I prefer using INT fields for primary keys. In this scenario everything is working fine. I am now thinking of using an external identity provider such as Azure Active Directory however I cannot work out how I would link a user in Azure AD (or any other identity provider) to my local database tables to maintain the

In MVC6 how can I block direct access to a folder in wwwroot?

被刻印的时光 ゝ 提交于 2019-12-06 01:43:20
问题 We're developing an application in the latest MVC framework and everything so far has been great. In our application we have decided to embed an angular application in the project under wwwroot/app. I created an app controller and view and prohibited access to the app unless users are authorized. This works great when unauthorized users try to go to localhost/app - it kicks them back to the C# application login page. I want to take it a step further and also prohibit access to direct files in

Is there a session start equivalent in .Net Core MVC 2.1?

五迷三道 提交于 2019-12-06 01:23:03
In MVC 5 you could assign a value to session in global.asx when the session started. Is there a way you can do this in .Net Core MVC? I have session configured but in the middleware it seems to get called on every request. nercan's solution will work, but I think I found a solution that requires less code and may have other advantages. First, wrap DistributedSessionStore like this: using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Session; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Logging; public interface IStartSession { void

How to self-host ASP.NET 5 MVC6 application

陌路散爱 提交于 2019-12-06 00:53:51
Just started learning ASP.NET 5 / MVC 6 I'm curious about self-hosting such an app outside of IIS - as a Windows service. Should I be using TopShelf for that, like it was the case with OWIN/Katana apps, or does ASP.NET 5 provide some built-in self-hosting (as a service) options via a NuGet package? You can use the Kestrel library for self-hosting. Add dependency to the library in the project.json file: "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", // Dependencies deleted for brevity. "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final" } Then scecify this command for Kestrel

Resize uploaded image in MVC 6

纵然是瞬间 提交于 2019-12-06 00:39:13
问题 What is the best way to resize an uploaded image in MVC 6? I'd like to store multiple variants of an image (such as small, large, etc.) to be able to choose which to display later. Here's my code for the action. [HttpPost] public async Task<IActionResult> UploadPhoto() { if (Request.Form.Files.Count != 1) return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest); IFormFile file = Request.Form.Files[0]; // calculate hash var sha = System.Security.Cryptography.SHA256.Create(); byte[] hash

Returning exceptions as JSON messages

眉间皱痕 提交于 2019-12-06 00:09:33
问题 I am developing an API with ASP.NET Core and I am struggling with the exception handling. When any exception occurs, or in any controller where I want to return custom errors with different status codes, I want to return JSON-formatted exception reports. I do not need an HTML in the error responses. I'm not sure if I should use middleware for this, or something else. How should I return JSON exceptions in an ASP.NET Core API? 回答1: An exception filter (either as an attribute, or a global

Asp.net Core Authorize Redirection Not Happening

 ̄綄美尐妖づ 提交于 2019-12-05 23:46:10
问题 I am trying to use cookie authentication in an Asp.net core app (dnx 4.5). Note that because I have a custom authentication mechanism (radius), I am not using the out-of-the-box mechanism provided by core Authentication. When the user is not authenticated I want to redirect to a login page. I have added in Startup.cs the following code. The idea is to be redirected to the Login Controller when the user has not been authenticated: app.UseCookieAuthentication(options => { options.LoginPath =