asp.net-mvc-5

Where can I load the user information to the session in ASP.NET MVC 5 with windows authentication?

ε祈祈猫儿з 提交于 2019-12-05 08:32:29
I want to use the ASP.NET MVC 5 for my web app. I need use the windows authentication . If I use the windows authentication where is the best place for reading user information (userid and roles) and store its to the Session ? I have the method for getting the user information by username from the database like this: public class CurrentUser { public int UserId { get; set; } public string UserName { get; set; } public Roles Roles { get; set; } } public enum Roles { Administrator, Editor, Reader } public class AuthService { public CurrentUser GetUserInfo(string userName) { var currentUser = new

EF Core with ASP MVC .NET 4.6

六月ゝ 毕业季﹏ 提交于 2019-12-05 08:12:34
In a project I need to set up an ASP.NET MVC (with .NET 4.6.1) but using the "new" EF Core for accessing the database. Unfortunately every documentation explains only how to setup an ASP.NET Core MVC project. I just gave it a try and when it comes to creating the database via the Package Manager Console I get the error message: No parameterless constructor was found on 'DataContext'. Either add a parameterless constructor to 'DataContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'DataContext' Yes, I don't have a parameterless constructor but neither does the

ASP.NET MVC 5 Model-Binding Edit View

廉价感情. 提交于 2019-12-05 07:52:39
I cannot come up with a solution to a problem that's best described verbally and with a little code. I am using VS 2013, MVC 5, and EF6 code-first; I am also using the MvcControllerWithContext scaffold, which generates a controller and views that support CRUD operations. Simply, I have a simple model that contains a CreatedDate value: public class WarrantyModel { [Key] public int Id { get; set; } public string Description { get; set; } DateTime CreatedDate { get; set; } DateTime LastModifiedDate { get; set; } } The included MVC scaffold uses the same model for its index, create, delete,

Custom Asp.net mvc 5 authentication without using Microsoft.AspNet.Identity.EntityFramework

a 夏天 提交于 2019-12-05 07:16:44
How do you create a custom ASP.NET MVC 5 Auth without using the UserStore of Microsoft.AspNet.Identity.EntityFramework?? All you have to do is implement the same interfaces that the Userstore for Identity.Entityframework uses. User will be your user class public class MyUserStore<TUser> : IUserLoginStore<TUser, int>, IUserClaimStore<TUser, int>, IUserRoleStore<TUser, int>, IUserPasswordStore<TUser, int>, IUserSecurityStampStore<TUser, int>, IUserStore<TUser, int>, IDisposable where TUser : User { //Implement the interfaces you need } Then pass your MyUserStore into the UserManager each request

Where is the class ManageUserViewModel?

大兔子大兔子 提交于 2019-12-05 07:11:32
I have created a project using ASP.Net MVC 5, EF 6 and .Net 4.5.1 At some point I needed to change the namespace that the project is in, from "MyTestProject" to "MyRealProject". After making those changes throughout the web site I now get several errors in a couple of my views. _ChangePasswordPartial.cshtml can't find "@model Microsoft.AspNet.Identity.ManageUserViewModel" any longer and _SetPasswordPartial.cshtml can't find "MyRealProject.ManageUserViewModel" No where in the project can I find a file that contains the class ManageUserViewModel. Before I changed the namespace it was found but

Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult

倖福魔咒の 提交于 2019-12-05 06:49:08
I've set up this test method on a controller to strip out any complication to it. Based off of all the results I've found from searching this should work. I'm not sure what I'm missing here. public JsonResult test() { return Json(new { id = 1 }); } This is the error I get. Cannot implicitly convert type 'System.Web.Http.Results.JsonResult' to 'System.Web.Mvc.JsonResult' you should return a JsonResult instead of just Json public JsonResult test() { var result = new JsonResult(); result.Data = new { id = 1 }; result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return result; } Try the

AngularJs and ASP.NET MVC 5 - ng-model overriding textbox value

荒凉一梦 提交于 2019-12-05 06:44:21
I have a form built using ASP.NET MVC 5 using @Html.TextBoxFor to populate the form with my model (e.g, after a form navigation or server side validation failure). I have now introduced a client side address lookup using Angular which means some of the form fields are now decorated with ng-model to enable the Angular lookup to populate the searched address. e.g.: @Html.TextBoxFor(m => m.Town, new { @class="form-control", ng_model="address.town" }) Adding the ng-model now overrides the value set from the MVC model when the page is reloaded. Viewing the source in the browser shows that the

Result of LINQ Query in MVC SelectList as Value and Text - not working

醉酒当歌 提交于 2019-12-05 06:42:47
I am trying to use the result of a LINQ Query to populate a SelectList in a MVC 5 application. The LINQ query returns customer IDs. Model public partial class Pricelist { public int CustomerID { get; set; } public int SelectedCustomer { get; set; } public Pricelist(int customerID, int selectedCustomer) { } } View @Html.DropDownList("custList") Controller (1) var query = ((from s in db.Pricelists select s.CustId).Distinct()).ToList(); int i = 1; List<Pricelist> CustomerList = new List<Pricelist>(); foreach (var c in query) { int cust = c; Pricelist p = new Pricelist(i, cust); CustomerList.Add(p

How to add new Scaffold used in Visual Studio 2013 Scaffolding?

拜拜、爱过 提交于 2019-12-05 06:36:43
Is there a way to add a new Scaffold or override the Scaffolding functionality used in the new Visual Studio 2013 Scaffolding? The only documentation I can find on the internet is how to override the T4 templates using the CodeTemplates folder. I want to add a new Scaffold to the list when Add... > New Scaffold Item... It looks like in Visual Studio 2013 this has been rolled into a library (Microsoft.AspNet.Scaffolding.Mvc.5.0.dll) and registered in the GAC or as a VS Extension. http://weblogs.asp.net/imranbaloch/archive/2013/09/15/customizing-the-asp-net-mvc-5-web-api-2-scaffolding-templates

what are the differences between [DataType(DataType.EmailAddress)] & [EmailAddress]

烂漫一生 提交于 2019-12-05 06:32:55
I am trying to understand what are the main differecnes between using [DataType(DataType.EmailAddress)] & [EmailAddress] . inside a model class:- public class MYViewModel { [DataType(DataType.EmailAddress)] OR [EmailAddress] public string Email { get; set; } i did a test and the two attributes will do the following:- will prevent users from adding invalud email address will display the value as "EmailTo:..." but i can not find any differences in respect to the functionality , of course if i use html.TextboxFor then the Datatype will not have any effect, while if i use html.EditorFor then the