asp.net-mvc-5

Extending asp.net mvc 5 identity with custom tables

最后都变了- 提交于 2019-11-30 09:09:44
I have an asp.net mvc 5 application with individual user account security extended with user roles and centralized user administration (users can't create accounts, only application administrator, i.e. me, create accounts and assign roles to them). My user class looks something like this: public class ApplicationUser : IdentityUser { // User name, full name, e-mail etc.... } and it's stored in "AspNetUsers" table provided by identity... Now i need to expand this by adding CompanyID property to a ApplicationUser class and new table with company informations (already existing in database)... Can

Multiple forms on one MVC form, created with a loop, only the first submits data

萝らか妹 提交于 2019-11-30 09:08:13
问题 I have the following code, only the first form submits anything, the following submit null values, each model has data. If I change it to just one large form, everything submits. Why do the other individual forms post null values? View @model myModel[] <ul> @for (int i = 0; i < Model.Length; i++) { using (Html.BeginForm("controllerAction", "Controller", FormMethod.Post, new { id="Form"+i })) { <li> @Html.TextBoxFor(a => a[i].property1) @Html.CheckBoxFor(a => a[i].property2) @Html.HiddenFor(a

How does redirect to returnUrl work in Asp.Net MVC5

妖精的绣舞 提交于 2019-11-30 09:04:09
I've started a new MVC 5 site, using the new Asp.Net Identity with Owin. In my "account" controller which has the attribute [Authorize], I have fairly standard actions; // GET: /User/Login [AllowAnonymous] public ActionResult Login(string returnUrl) { ViewBag.ReturnUrl = returnUrl; return View(); } // POST: /User/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { try { if (ModelState.IsValid) { var userApi = new UserService(); var apiUser = await userApi.LogIn(UserManager, model.CardNumber, model.Pin,

How to logout user in OWIN ASP.NET MVC5

99封情书 提交于 2019-11-30 08:57:08
I have got a standard AccountController class of ASP.NET MVC5 project. When I try to log out user I am facing an error coz HttpContext is null . (I mean here HttpContext .GetOwinContext().Authentication is null) So I cannot get how we can logout user when session ends... In global.asax I have got this protected void Session_Start(object sender, EventArgs e) { Session.Timeout = 3; } protected void Session_End(object sender, EventArgs e) { try { var accountController = new AccountController(); accountController.SignOut(); } catch (Exception) { } } AccountController public void SignOut() { //

asp.net waiting for localhost forever

泪湿孤枕 提交于 2019-11-30 08:54:22
问题 Suddenly this morning I turned on my computer and launched visual studio... And no matter what I tried and whether I run or debug, and whatever the browser is ( chrome / firefox / IE 11 ) it is waiting for localhost forever. If I deploy it to azure, by just checking in ( continuous integration ) it works like a charm I've read both: Waiting for localhost, forever! How to figure out why my local host site takes so long to load? As I write, it has been waiting for localhost for more than 15mins

In Visual Studio 2013 / ASP.NET MVC 5, How do I add a new Controller?

ぐ巨炮叔叔 提交于 2019-11-30 08:52:48
In ASP.NET MVC5 + VS 2013 (preview at time of writing), how do I add a new Controller? In past versions (VS 2012 / MVC 4), I was able to right click on the Controllers folder and click "Add Controller". That option is no longer there. Where did it go? (Side note: I am not certain if MVC 5 is where the change takes place or if it a change in the VS 2013 tooling as I updated both. I suspect it is with the new ASP.NET tooling for VS 2013) Updated this answer on Nov 14 2013, after the official VS2013 release to reflect changes in the final release -ds For Visual Studio 2013 (Released Version) Note

CSS/JS bundle in single file in mvc when publish with release option

泄露秘密 提交于 2019-11-30 08:46:00
I have created MVC application. When I publish the application on Azure with release option, all css and js file load in a single bundle in page. (Open view source of page then displays a single link for css). When I publish a site with Debug option in publish profile then all CSS load individual. My problem is when publish site with release option theme not load correctly, but with debug option theme loads correctly. I want to publish my application with Release option only. If anyone face this issue before and get any solution then please help me. I have experienced this before when using

Custom Authorization filter in ASP.NET MVC 5?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 08:45:36
问题 In ASP.NET MVC 5 we can use [Authorize] attribute to check authorization and limit access to some actions\pages. I wonder how can I modify this attribute - authorization should be checked after some period of time? For instance, let unauthorized user to see the page during 10 minutes and then block access . Updated : it is seems that my question wasn't clear so I bolded the problem. I need to count time each unauthorized user spent on the site and then block him after N minutes. 回答1: You may

System.Data.Entity.Core.ProviderIncompatible Exception in MVC 5

风格不统一 提交于 2019-11-30 08:38:18
I am creating an ASP.NET Web Application in mvc5 and i made a model class with a controller. My application is running but when i want to access my moviescontroller in url like localhost:1234/Movies it generates an exception in my MoviesController.cs file The connection string that I'm using is <connectionStrings> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20130819083100.mdf;Initial Catalog=aspnet-MvcMovie-20130819083100;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="MovieDBContext"

How to bind view model property with different name

戏子无情 提交于 2019-11-30 08:38:17
Is there a way to make a reflection for a view model property as an element with different name and id values on the html side. That is the main question of what I want to achieve. So the basic introduction for the question is like: 1- I have a view model (as an example) which created for a filter operation in view side. public class FilterViewModel { public string FilterParameter { get; set; } } 2- I have a controller action which is created for GETting form values(here it is filter) public ActionResult Index(FilterViewModel filter) { return View(); } 3- I have a view that a user can filter