asp.net-mvc-5

How can I limit the serving of a javascript file to only authenticated users?

核能气质少年 提交于 2019-11-30 13:43:17
I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns data to only authenticated and authorized users. Dalorzo You can force the static files to go through the

Is there a way to have a SetUpFixture that runs once per class instead of once per namespace?

北城以北 提交于 2019-11-30 13:40:08
问题 Scenario First of all, I'm new to testing - so please bear with me. Inside of my test project , there is a Controllers folder. The Controllers folder may contain a ControllerATest.cs, ControllerBTest.cs, and ControllerCTest.cs. Because my namespace aligns with my folder structure, they all share the namespace MyProject.Tests.Controllers. From what I've read in the NUnit SetUpFixture Documentation, a [SetUpFixture] inside this namespace will run once for the entire namespace . That is, if I

Migrating to Asp.Net Identity 2.0: new columns not being created in AspNetUsers table

假装没事ソ 提交于 2019-11-30 13:22:40
问题 I get the following error when I try to register a new user, using Identity 2.0 and the default MVC 5 application: Invalid column name 'Email'. Invalid column name 'EmailConfirmed'. Invalid column name 'PhoneNumber'. Invalid column name 'PhoneNumberConfirmed'. Invalid column name 'TwoFactorEnabled'. Invalid column name 'LockoutEndDateUtc'. Invalid column name 'LockoutEnabled'. Invalid column name 'AccessFailedCount'. (repeats 2 more times, I have a total of 4 test users in AspNetUsers table.)

Posting A String Array

走远了吗. 提交于 2019-11-30 13:08:21
How can I handle an array of input For example I have in my view: <input type="text" name="listStrings[0]" /><br /> <input type="text" name="listStrings[1]" /><br /> <input type="text" name="listStrings[2]" /><br /> In my control I try to get the values like: [HttpPost] public ActionResult testMultiple(string[] listStrings) { viewModel.listStrings = listStrings; return View(viewModel); } On debugging I can see listStrings is null every time. Why is it null and how can I get the values of the input array Posting a Collection of Primitives With ASP.NET MVC To post a collection of primitives the

How to use ASP.NET Identity without a database

邮差的信 提交于 2019-11-30 12:35:47
问题 I am trying to implement custom authentication using the new ASP.NET Identity in an MVC 5 project. I have a single username and password that I want to use to restrict which pages of the website the user can see via [Authorize] tags on controllers and views. (Easy) I am migrating from a FormsAuthentication model whereby this was as simple as putting the credentials in the web.config. Because I only have a single username and password I don't want to use a database as the UserStore , instead I

ASP.Net MVC 5 w/identity 2.2.0 Log off not working

天涯浪子 提交于 2019-11-30 12:26:25
问题 I am using a the basic login on a test ASP.Net MVC 5 site (for an internet site). The login works fine but when I try to logout it doesn't happen. The logout link does call the following controller action: public ActionResult LogOff() { AuthenticationManager.SignOut(); return RedirectToAction("Index", "Home"); } But the user stays logged in. How do I ensure that the user actually gets logged out? 回答1: I had this problem before, change: AuthenticationManager.SignOut(); To:

How do I get an instance of IAppBuilder elsewhere in my ASP.NET MVC 5.2.3 application?

巧了我就是萌 提交于 2019-11-30 12:12:16
I need to build an Owin middle-ware object but not from within the Startup class. I need to build it from within anywhere else in my code, so I need a reference to the AppBuilder instance of the application. Is there a way to get that from anywhere else? You could simply inject AppBuilder itself to OwinContext . But since Owin context only supports IDisposable object, wrap it in IDisposable object and register it. public class AppBuilderProvider : IDisposable { private IAppBuilder _app; public AppBuilderProvider(IAppBuilder app) { _app = app; } public IAppBuilder Get() { return _app; } public

Setting the redirect_uri in Asp.Net Identity

余生长醉 提交于 2019-11-30 12:06:05
问题 I am trying to set the redirect_uri for the facebook login with Asp.Net Identity. However, the GetExternalLogin REST method in the AccountController is only triggered if the redirect_uri is '/'. If I add anything else it does not trigger GetExternalLogin , the browser only shows error: invalid_request . However the url contains the redirected parameter as it should e.g. if I add the redirect_uri as http://localhost:25432/testing the response URL looks like this: http://localhost:25432/api

MVC5: Enum radio button with label as displayname

被刻印的时光 ゝ 提交于 2019-11-30 11:50:16
I have these enums public enum QuestionStart { [Display(Name="Repeat till common match is found")] RepeatTillCommonIsFound, [Display(Name="Repeat once")] RepeatOnce, [Display(Name="No repeat")] NoRepeat } public enum QuestionEnd { [Display(Name="Cancel Invitation")] CancelInvitation, [Display(Name="Plan with participants on first available common date")] FirstAvailableCommon, [Display(Name="Plan with participants on my first available common date")] YourFirstAvailableCommon } and I have a helper class to show all the radiobutton for each field in enum @model Enum @foreach (var value in Enum

PagedList error: The method 'OrderBy' must be called before the method 'Skip'

岁酱吖の 提交于 2019-11-30 11:49:15
Here's the full error message: The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip' In the "PurchaseOrderController" I have added this code to the index method: // GET: PurchaseOrder public ActionResult Index(int? page) { return View(db.PurchaseOrders.ToPagedList(page ?? 1, 3)); } Also in the Index View for "PurchaseOrders" I have added this code: @using PagedList; @using PagedList.Mvc; @model IPagedList<PurchaseOrders.Models.PurchaseOrder> @{ ViewBag.Title = "Index"; } <h2>Index</h2> <p> @Html.ActionLink("Create