asp.net-core-mvc

Cookies in ASP vnext

巧了我就是萌 提交于 2020-01-23 06:35:46
问题 How can i use cookies in ASP MVC 6? I want to set and read cookie variables . HttpCookie class can't be resolved . Only the following line works but i couldn't find a way to read the cookie after adding it . Response.Cookies.Append("test", "test"); 回答1: Take a look at how cookies are used in the official MusicStore sample: https://github.com/aspnet/MusicStore/blob/a7ba4f8ffe5ed23b2a2d55e8e1226e64066a7ada/src/MusicStore/Models/ShoppingCart.cs#L152 public string GetCartId(HttpContext context) {

Client Side Deep Links with WebpackDevMiddleware 404s

空扰寡人 提交于 2020-01-23 04:58:08
问题 I am using the WebpackDevMiddleware for Development builds to serve up a Vue.js application that uses client-side routing. The SPA application is served up from the root url just fine, but if I attempt to use any client-side deep links, I get a 404. Note running as Production works as expected. What I want: http://locahost/ - serve up the vue app. http://localhost/overlays/chat - serve up the vue app. http://localhost/api/* - serve up the api routes handled server side. There is a minimum

Has something replaced bundleconfig.json in ASP.NET Core MVC 2.1?

冷暖自知 提交于 2020-01-23 04:15:13
问题 When I create a new ASP.NET MVC Core targeting 2.1 RC1, it doesn't create the bundleconfig.json file which is used for bundling and minification. This file is created if I target 2.0. Here is a example, the solution contains a new project targeting 2.0 and another targeting 2.1: Has something replaced the builtin bundling and minification, or is this just a bug in RC1? 回答1: bundleconfig.json was removed from the 2.1 templates because it relied on a tool not created or supported by Microsoft.

ASP.NET 5 MVC6 User.GetUserId() returns incorrect id

ε祈祈猫儿з 提交于 2020-01-23 01:33:32
问题 I have simple project in ASP.NET 5 with one registered user. I have tried to get id of current logged user by extension method GetUserId() from using System.Security.Claims namespace. Unfortunately this method returns me not existing id and i don't know why. Here is my simple code: var currentUserId = User.GetUserId(); Method result: Database: 回答1: More than likely you're getting an old auth ticket that is still valid OR your getting an authentication ticket for another site your running

reference is not added in ASP.Net MVC 6 for "Microsoft.BingAds.SDK”

眉间皱痕 提交于 2020-01-22 16:49:07
问题 I am doing this project in mvc6 using asp.net framework 6.how I can add this reference in my project please help me. 回答1: You have to talk to BingAds and ask them for a compatible version. This is the same with every library provider, they all must support the new platform. You cannot add a library which targets .NET 4.x, they must rewrite and publish a new version/ 来源: https://stackoverflow.com/questions/36194075/reference-is-not-added-in-asp-net-mvc-6-for-microsoft-bingads-sdk

Passing TempData with RedirectToAction

爱⌒轻易说出口 提交于 2020-01-22 13:34:08
问题 Intro: I am a .NET studet trying to learn ASP.NET Core MVC. So please be understanding. I have searched the web for an answer to my problem, but havent found a solution that works for me. Problem: I want to pass a validation message from my create post method to the index IActionmethod whenever a post has been created and them show it as an alert message for now. I have read on the web that ViewBag dosent survive a redirect, but a TempData does. This is my code so far. Create post method:

Handling exception in asp.net core?

落爺英雄遲暮 提交于 2020-01-22 10:36:24
问题 I have asp.net core application. The implementation of configure method redirects the user to "Error" page when there is an exception ( in non Development environment) However it only works if the exception occurs inside controller. If exception occurs outside of controller, for example in my custom middleware, then the user does not get redirected to error page. How do i redirect user to "Error" page if there is an exception in the middleware. public void Configure(IApplicationBuilder app,

Where all types for http headers gone in ASP.NET 5?

此生再无相见时 提交于 2020-01-21 10:38:47
问题 Previously, in WebApi (on .NET 4.x) we could work with headers of both the request and the response via typed interfaces (see HttpRequestMessage.Headers / HttpResponseMessage.Headers ). Now, in ASP.NET 5 we have HttpRequest and HttpResponse with Headers property of type IHeaderDictionary . But it's just an untyped Dictionary. Below I put an example with typed accessing could return a fine-tuned http-response. It's needed to create a HttpResponseMessage and fill its Headers collection (which

Testing user if he has a specific authority using AuthorizeAsync() in Xunit-Unit Testing

烂漫一生 提交于 2020-01-21 08:46:27
问题 The question has been Updated for better explanation to the issue I have, Simply I have this controller, [Authorize] public class IdeaManagementController : Controller { private IIdeaManagementService _ideaManagementService; private ITenantService _tenantService; private ITagService _tagService; private IEmployeeIdeaCategoryService _ideaManagementCategoryService; private static PbdModule _modul = PbdModule.IdeaManagement; IAuthorizationService _authorizationService; public

TagHelpers add custom class for LabelTagHelper based on validation attribute [Required]

北慕城南 提交于 2020-01-21 05:54:06
问题 In Core MVC there is anew concept as Tag helpers. We could previously create custom html helpers to attach some classes based on the validation data annotations such as [Required]. As TagHelpers arq quite new area I cannot find anough resources to achieve the following: here is the view model: [Required] public Gender Gender { get; set; } view: <label class="control-label col-md-3 required" asp-for="Gender"></label> css: .required:after { content: "*"; font-weight: bold; color: red; } output: