asp.net-mvc-5

How to delete users that were created with UserManager.CreateAsync

老子叫甜甜 提交于 2019-12-09 17:03:09
问题 Using asp.net mvc5, my user management systems seems to work. I can login with google or with name/password.. but now I am working on a user management interface in which I need to be able to delete existing users. And this is starting to expose to me just how confusing the user management system is. There's so many different ways to deal with users.. and some of them don't work. Most everywhere I read, it is talking about using the Membership.DeleteUser(). But that isn't working... The users

Unity Bootstrapper from NuGet is throwing error on App_Start

拥有回忆 提交于 2019-12-09 15:40:16
问题 the Microsoft Unity Bootstrapper for Unity 3.0 is throwing an error on this line: FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container)); with the following error: An exception of type 'System.ArrayTypeMismatchException' occurred in mscorlib.dll but was not handled in user code Additional information: Attempted to access an element as a type incompatible with the array. The entirety of the code is here and this was all pre-made and written by the bootstrapper

Calling Async Methods in Action Filters in MVC 5

丶灬走出姿态 提交于 2019-12-09 15:01:08
问题 I'm writing an Action Filter (inheriting from ActionFilterAttribute ) which uses HttpClient to POST data to an external server in the OnResultExecuted method. HttpClient has the method PostAsync which returns an awaitable Task<HttpResponseMessage> . public override void OnResultExecuted(ResultExecutedContext filterContext) { using (var client = new HttpClient()) { var task = client.PostAsync(GetUri(), GetContent()); var result = task.Result; // blocking } } The accepted answer to Async action

Async Action Methods

。_饼干妹妹 提交于 2019-12-09 14:16:43
问题 I was looking at ASP.NET MVC 5 templates and I have notice that many of the actions and marked as async: public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { } When should I do this on an MVC action? When it contains access to a database? If I call a repository inside the action should I also use Task to make it async? 回答1: The core of your questions is: When should I make my MVC actions async? See http://blogs.msdn.com/b/rickandy/archive/2009/11/14/should-my

Attribute routing with http PUT method constraint

99封情书 提交于 2019-12-09 13:42:06
问题 I'm using the new attribute routing with MVC5 and have gotten http GET and POST method constraints to work by adding the [HttpGet] and [HttpPost] attributes to my action methods. But when I add [HttpPut] I just get a 404 error page. Does anyone know what I need to do to get attribute routing working with http PUT ? See code below: [HttpGet] [Route("edit")] public ActionResult Edit() { // this works return View(); } [HttpPost] [Route("insert")] public ActionResult Insert() { // this works

With ASP.NET MVC 5 and Bootstrap 3 default install, why do styles get a 403 error and fonts throw a 404?

∥☆過路亽.° 提交于 2019-12-09 09:39:48
问题 With a default install of ASP.NET MVC 5 and an updated Bootstrap 3, loading my project's home page does not display CSS styles or the included font glyphicons (404 file not found error). The CSS styles get a 403 "Forbidden to view folder contents" error to the /Content/css address. The fonts get a 404 error to /fonts folder. Why? 回答1: When you install Bootstrap 3 into the Content folder, it includes a folder structure like this: ~/Content/css/boostrap.min.css ~/Content/fonts/glyphincons

MapMvcAttributeRoutes: This method cannot be called during the application's pre-start initialization phase

我们两清 提交于 2019-12-09 07:26:39
问题 I have a very simple test in a test project in a solution using ASP MVC V5 and attribute routing. Attribute routing and the MapMvcAttributeRoutes method are part of ASP MVC 5. [Test] public void HasRoutesInTable() { var routes = new RouteCollection(); routes.MapMvcAttributeRoutes(); Assert.That(routes.Count, Is.GreaterThan(0)); } This results in: System.InvalidOperationException : This method cannot be called during the applications pre-start initialization phase. Most of the answers to this

MVC 5 Role Based Authentication

余生长醉 提交于 2019-12-09 07:05:23
问题 I am trying to lock down our "admin" page to only admins using Asp.net Identity (we are building in MVC5). I can get [Authorize(Users="admin")] to work but can not get [Authorize(Roles="Admin")] to work. I have created the role in the dbo.AspNetRoles table and then associated the account in the AspNetUserRoles by pairing the user GUID to the ID in the aspnetroles table. I have seen in previous editions of MVC you have had to get into web.config to add some lines. Can anyone help point me in

When deploying MVC app on server ajax cant find action but Localhost it does

ぃ、小莉子 提交于 2019-12-09 03:58:53
问题 I have a MVC5 application. When I run it on my localhost everything works without any errors. When I publish my app then I transfer it to Windows Server 2016, I put the files in wwwroot in the IIS folder and I link everything to create a new website in IIS. I then run the website and it works. I get my javascript code to work, but when I go and run my ‘ajax’ methods I get an 404 error and in the function I cannot find my controller action so the method will work. Here is my actual error: xxx

row span using MVC5

这一生的挚爱 提交于 2019-12-08 23:03:33
@if (ViewData["post"] != null) { foreach (var item in ViewData["post"] as IEnumerable<Employee.Models.ApplyJob>) { <tr> <td>@item.PerferenceNo</td> <td>@item.JobName</td> <td>@item.Location</td> <td>Action</td> </tr> } } how to use row span on PerferenceNo and JobName using MVC4> You need to compare the previous values with the current values, but there is no need to use rowspan (which would unnecessarily complicate it). You can just generate an empty <td> element when the cell matches the previous value. @{ var data = ViewData["post"] as IEnumerable<Employee.Models.ApplyJob>; int perferenceNo