asp.net-core-mvc

How to handle cookie expiration in asp.net core

三世轮回 提交于 2019-12-03 16:17:59
I would like to know how to properly handle the fact that the cookie expired? Is it possible to execute a custom action ? What I would like to achieve is that when the cookie is expired is to take few informations out of the current cookie at redirect to a action parametrise by this information. Is it possible ? Looks like you need your own handler for OnValidatePrincipal event when setuping cokies auth middleware: OnValidatePrincipal event can be used to intercept and override validation of the cookie identity app.UseCookieAuthentication(options => { options.Events = new

Getting reference of Startup.cs object

浪尽此生 提交于 2019-12-03 15:31:23
Here's the skeleton of a standard ASP.NET Core application: var config = new ConfigurationBuilder() .AddCommandLine(args) .AddEnvironmentVariables(prefix: "ASPNETCORE_") .Build(); var host = new WebHostBuilder() .UseConfiguration(config) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); In this piece the ASP.NET Core apparatus instantiates an instance of Startup.cs class .UseStartup<Startup>() My query is how can I get hold (reference) of this already instantiated instance of Startup object that I can plug into my

.Net Core Image Manipulation (Crop & Resize) / File Handling

落爺英雄遲暮 提交于 2019-12-03 15:24:55
问题 I have spent the last 5 hours trying to find a feasible way to accomplish what seems to me quite an easy task if it was a previous version of the .NET family that I was working with: Uploading a picture Resizing & Cropping the picture Saving the new picture into a directory I have come accross to couple of libraries that are either in pre-release stage or in a not-complete stage. Has anyone at all accomplished the above tasks without specifically including the System.Drawing namespace and/or

Logging to database in ASP.NET Core MVC 6

♀尐吖头ヾ 提交于 2019-12-03 15:23:11
In my old MVC5 project all log informations was saved on a sql server database through log4net. I would like keep logger structure of ASP.NET 5 without using any more the log4net. Is it possibile saving the logs on a database table? What kind of code should I use? You can implement ILoggerFactory and ILogger however you like including, for example, logging to a database. Here's an example of an ILogger implementation that uses EntityFramework 6 to save logs to a database. I've created new project that is a bit more flexible and available for Entity Framework Core. Here is the GitHub project

MVC6 alternative to @Html.DisplayFor

喜夏-厌秋 提交于 2019-12-03 15:08:11
问题 MVC6 introduces Tag Helpers which is a better way compared to using @Html.EditorFor, etc. However I have not found any Tag Helper that would be an alternative to @Html.DisplayFor. Of course I can use a variable directly on a Razor page, such as @Model.BookingCode. But this does not allow to control formatting. With MVC6, what's conceptually correct way for displaying a value of a model property? 回答1: You can create your own tag helper namespace MyDemo.TagHelpers { [HtmlTargetElement("p",

App_Data directory in ASP.NET5 MVC6

我们两清 提交于 2019-12-03 15:01:35
问题 I've been trying ASP.NET5 MVC6 app. In the previous version, there was a directory App_Data . I used this folder to store error logs. But it is not found in latest version. Any help? 回答1: This works for ASP.NET MVC with Core 2 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { // Use this code if you want the App_Data folder to be in wwwroot //string baseDir = env.WebRootPath; // Use this if you want App_Data off your project root folder string baseDir = env

DateTime Data Annnotations do not work in ASP.NET Core RC2 application

与世无争的帅哥 提交于 2019-12-03 14:57:54
if I add Data annotations to my ViewModel the value of the DateTime field is always {1/1/0001 12:00:00 AM}. ViewModel public class EditReleaseViewModel : BaseViewModel { [Display(Name = "ReleaseDate", ResourceType = typeof(SharedResource))] [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy HH:mm}")] [Required(ErrorMessageResourceName = "FieldRequired", ErrorMessageResourceType = typeof(SharedResource))] public DateTime ReleaseDate { get; set; } } The controller is very straightforward, if I remove the data annotation and use the default everything works fine.

Windows Authentication support in ASP.NET 5 beta 8

时光毁灭记忆、已成空白 提交于 2019-12-03 14:45:42
I have an ASP.NET 5 MVC 6 Web API project. Most of the API endpoints have the [Authorize] attribute, and Windows Authentication is enabled in both IIS and on the properties of the project in Visual Studio. This all works fine in beta 7. In beta 8, however, this does not work. It's easy to reproduce this with a completely clean project: Create a new project using the ASP.NET 5 Web API template. Get properties on the project (not the solution), go to the Debug tab, enable Windows authentication and disable Anonymous. Save the changes. Hit F5 and let it attempt to run the project. Result: An

ASP.NET 5 RC1: System.IO.InvalidDataException: Unexpected end of request content

谁都会走 提交于 2019-12-03 14:35:53
I am running an ASP.NET 5 project in an Azure Web App. When calling on an API endpoint with a file (form-data) of about 1.5mb or larger, the following exception is thrown. Here is where the exception is thrown from . Does anyone know how this can be fixed? Is there a possible workaround? System.IO.InvalidDataException: Unexpected end of request content at Microsoft.AspNet.Server.Kestrel.Http.MessageBody.ForContentLength.d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at

MVC 6 WebFarm: The antiforgery token could not be decrypted

我是研究僧i 提交于 2019-12-03 14:22:49
I'm running MVC 6 (vNext) in a webfarm scenario (ARR front-end with multiple AppServers). Server affinity is off. When I bounce between app servers from one request to another I get the error CryptographicException: The key {3275ccad-973d-43ca-930f-fbac4d276640} was not found in the key ring. InvalidOperationException: The antiforgery token could not be decrypted. Previously, I believe this was handled by setting a static MachineKey in the web.config. As I understand it, we've now moved to a new DataProtection API and I've tried the following, thinking the application name is used as some kind