asp.net-core-mvc

.NET Core forward a local API form-data post request to remote API

好久不见. 提交于 2019-12-04 07:03:45
I have an AJAX form which post a form-data to a local API url: /api/document . It contains a file and a custom Id. We simply want to take the exact received Request and forward it to a remote API at example.com:8000/document/upload . Is there a simple way of achieve this "forward" (or proxy?) of the Request to a remote API using Asp.NET Core? Below we had the idea to simply use Web API Http client to get the request and then resend it (by doing so we want to be able to for example append a private api key from the backend ), but it seems not to work properly, the PostAsync doesn't accept the

ASP.NET Core MVC, Get file from database, and render as image

爱⌒轻易说出口 提交于 2019-12-04 07:03:38
I have image data being stored in a SQL table with a field type of varbinary(max) I also store the image content type. Using Microsoft ASP.NET Core MVC and Dapper, I am trying to get the file back from the database and render it as an image. This is my FileModel : using System; namespace Brand.Models { public class FileModel { public Guid ID { get; set; } public string FileName { get; set; } public string FileType { get; set; } public byte[] FileData { get; set; } public int FileLength { get; set; } public long Version { get; set; } public string FileSource { get; set; } public DateTime

How to download PDF file on browser in Asp.net CORE MVC

泪湿孤枕 提交于 2019-12-04 06:50:36
问题 I am using below code which used to download SSRS report in pdf format: string URL = "http://ssrs-test.com/ReportS/?/UAT_FOLDER"; URL = URL + "&SRNo=122&rs:Command=Render&rs:Format=pdf"; System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest) System.Net.WebRequest.Create(URL); Req.Method = "GET"; string path = @ "E:\New folder\Test.pdf"; System.Net.WebResponse objResponse = Req.GetResponse(); System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create); System.IO

VS 2015 CTP 6 Nuget Package Source

谁说我不能喝 提交于 2019-12-04 06:45:48
After installing VS 2015 CTP 6 it added the following url to Available Package Sources: https://api.nuget.org/v3/index.json and turned off the following: https://www.nuget.org/api/v2/ When it did this it stopped downloading all nuget packages. I switched it back to the old one and everything is working again. One thing I noticed is that the old feed is xml and the new one is json. NOTE: I did upgrade the Nuget Package Manager after installing VS 2015 CTP 6. Is anyone else having this issue? Example Error: Error: FindPackagesById: System.Threading.Tasks Response status code does not indicate

ASP.Net Identity not persisting cookie MVC6 vNext

橙三吉。 提交于 2019-12-04 06:38:13
问题 I'm working on a MVC6 ASP.Net5 project, and am having trouble with .Net Identity persisting my authentication cookie on login. I am using a custom user store, this is an existing DB with existing stored procedures etc... My SignIn method is an extension on my User object, and follows. public static async Task SignIn(this UserModel Model, UserManager<UserModel> UserManager, SignInManager<UserModel> SignInManager, bool RemeberMe = true) { var Claims = new List<Claim>(); Claims.Add(new Claim(

Custom authorization attribute in .NET Core [duplicate]

自古美人都是妖i 提交于 2019-12-04 06:05:46
This question already has answers here : Closed 2 years ago . How do you create a custom AuthorizeAttribute in ASP.NET Core? (7 answers) I'm building an API in .NET Core 1.1. I build a custom User object from HttpContext.User in a base controller that all of my other controllers inherit from, and I have authentication enabled by default (must be manually disabled with [AllowAnonymous] when necessary). The User object has an IsAdmin property. Right now I'm checking if the user is an admin at the top of each relevant function like below, but I feel like there must be a way to add a custom

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

二次信任 提交于 2019-12-04 05:59:40
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 that folder such as localhost/app/scripts/controllers/name.js or partial html files /app/partials/name

ASP.NET 5 (vNext) Deployment via TFS 2015

浪尽此生 提交于 2019-12-04 05:37:20
We're trying to work through the new tool chain for building and deploying an ASP.NET 5 (vNext) CoreCLR web site to a server cluster. Between the new compilation changes and the changes to TFS, I'm not sure how everything now gets built and deployed. The scenario is as follows: On-premise TFS for source control and build agent Targeting ASP.NET 5 under CoreCLR, hosted via IIS Questions are: Using TFS for continuous integration builds (and hopefully deployment to an on-premise IIS server), how does one build and deploy this new application type? It seems like MSBuild might still be usable to

How to inject IHttpContextAccessor into Autofac TenantIdentificationStrategy

天涯浪子 提交于 2019-12-04 05:14:09
I am migrating my multitenant application from Webapi to aspnet core. In webapi version I was using TenantIdentificationStrategy that identified tenants based on request path on HttpContext . Moving to aspnet core, I am able to wire-up autofac successfully. I am not able to figure out how to wireup the tenant strategy. I tried injecting IHttpContextAccessor in ConfigureServices as services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); and my strategy looks like this public class AssetClassIdentificationStrategy: ITenantIdentificationStrategy { private readonly IHttpContextAccessor

Asp.net Core Authorize Redirection Not Happening

这一生的挚爱 提交于 2019-12-04 05:11:27
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 = new Microsoft.AspNet.Http.PathString("/Login"); }); In my Home controller I have: [Authorize] public