asp.net-mvc-5

Mapping User.Identity in .NET MVC app to active directory user

狂风中的少年 提交于 2019-12-03 18:15:32
I'm writing a .NET MVC 5 app which is on an intranet, uses Windows Authentication and needs to query Active Directory to see what groups are available and then check if a user is in that role. The source of group and user names will be active directory. I then need to check identity and membership using .NET Identity. I'm not sure what fields map to what. Fields of interest in AD seem to be: SamAccountName: I think this is the username that I get from User.Identity, but the docs say that this property is: The logon name used to support clients and servers running earlier versions of the

Wrong DateFormat with Jquery Datepicker

三世轮回 提交于 2019-12-03 18:12:18
问题 I want to exclude the time part in the DateTime Textbox, but I can't make it work the way I want. This is how I set up the field : @Html.TextBoxFor(m => m.DateFrom, "{0:dd/MM/yyyy}", new { @class = "datefrom" }) @Html.TextBoxFor(m => m.DateTo, "{0:dd/MM/yyyy}", new { @class = "dateto" }) Jquery script: $(function () { $(".datefrom").datepicker({ defaultDate: "+1w", changeMonth: true, numberOfMonths: 1, dateFormat: "dd/mm/yy", onClose: function (selectedDate) { $("#to").datepicker("option",

Attribute routing with http PUT method constraint

好久不见. 提交于 2019-12-03 17:17:49
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 return View(); } [HttpPut] [Route("update")] public ActionResult Update() { // this does not work return

POCO's with the new ASP.NET Identity and MVC 5.0 + claims-based Identity

狂风中的少年 提交于 2019-12-03 17:03:06
问题 With the new version of VS 2013 RTM and asp.net mvc 5.0, I’ve decided to try out a few things... Needless to say, a lot has changed. For example, the new ASP.NET Identity is a replacement of the old Membership and (less old) SimpleMembership APIs. In all previous applications I’ve built, I never had the chance to work with Membership or with SimpleMembership. I’ve always ended up creating my own Login() method which would convert a submitted ViewModel to a POCO (using automapper) which in

TextAreaFor Cannot Set Width

孤街浪徒 提交于 2019-12-03 16:30:08
问题 I cannot set the width or cols in atextarea. Rows/Height works just fine. can someone please help thanks! @using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) @Html.TextAreaFor(model => model.Comments, new {cols=60, rows=10}) @Html.HiddenFor(model => model.UserName, new { UserName = @User.Identity }) <div class="form-group"> <div class="col-md-10"> <input type="submit" value="Submit Feedback" class="btn btn-default" /> </div> </div> } Any advice or tips would be

Hiding links from certain roles in ASP.NET MVC5

自作多情 提交于 2019-12-03 16:27:30
问题 So this may sound a dumb question, but how do I show a link only for an admin user? Suppose an ordinary user sees the following links: Home / About / Contact And an admin user sees the following links: Home / About / Contact / Admin I tried restricting in the controller and linking the controller on the menu. But it still shows the link for everyone, just doesn't allow access to anyone but admin Can the views be overloaded? 回答1: Depending on what sort of Membership/User provider you are using

How do I mock controller context in my unit test so that my partial view to string function works?

落花浮王杯 提交于 2019-12-03 16:16:05
问题 I am attempting to create a unit test for my controller, but the action I am testing uses a partial view to string function which doesn't want to work in my tests. private string RenderPartialViewToString(string viewName, object model = null) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (System.IO.StringWriter sw = new System.IO.StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines

Populate DropDownList in MVC 5

隐身守侯 提交于 2019-12-03 16:04:31
Here is my code for my AddNewProductViewModel using AccessorizeForLess.Data; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Web; namespace AccessorizeForLess.ViewModels { public class AddNewProductViewModel { public string Name { get; set; } [DataType(DataType.MultilineText)] public string Description { get; set; } public decimal Price { get; set; } public string AltText { get; set; } public int Quantity { get; set; } public string ImagePath { get; set; } public HttpPostedFileBase Image { get; set; } public List<ProductCategory> Category { get; set;

How to remove schema node in web api if return format is xml?

断了今生、忘了曾经 提交于 2019-12-03 15:50:36
I have a web api method that takes format as a parameter that provides returning both xml and json.The data type that method return is DataTable.In json format everything looks fine but in xml format the schema of datatable and some other attributes in xml nodes also returning.How to return simple xml that includes only data of datatable?Also, I am using QueryStringMapping in WebApiConfig. This is WebApiConfig Code public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/

ASP.NET MVC 5 Identity 2.0, Windows Auth, User model with role attribute

折月煮酒 提交于 2019-12-03 15:43:16
I'm trying to create an MVC5 application that uses Windows Authentication but uses roles pulled from a User model. I've searched high and low for an example, but the only ones I can find are based on the old ASP.NET identity framework. Anyone care to point me in the right direction?! Thanks! So I've figured out one approach to solving this problem. I created a custom Authorization Attribute that checks the User model for a role. using System.Linq; using System.Web; using System.Web.Mvc; using App.Models; using System.Security.Claims; namespace App.Extensions.Attributes { public class