asp.net-mvc-5

Custom 401 error page for ASP.NET MVC application

ⅰ亾dé卋堺 提交于 2020-01-03 08:30:12
问题 I created an ASP.NET MVC application that uses integrated Windows Authentication. The following authorization logic was implemented: Try to get account credentials from active directory through NTLM. If credentials are received and the Windows account has required permissions then perform requested action. In otherwise go to clause 2. Display the Windows authentication dialog, so a user can provide another credentials: If another credentials are received and the user has required permissions

How to use a 'checkbox' to update present address to same as permanent address

浪尽此生 提交于 2020-01-03 06:36:18
问题 Often when creating a form on a web page, I need our customers to fill out a field such as a permanent address, as well as a present address( when checked check box then present address fill automatically). Instead of having our customers fill out the form twice,I can use JavaScript to copy the form's data from one field to another. @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div> <div class="well"> <b>Parmanent Address </b> </div> <div class="row"> <div class="col-md-6"> <div class

Model validation - Why ModelState.IsValid always returns true even when no values are supplied?

点点圈 提交于 2020-01-03 06:19:09
问题 This is regarding WEBAPI and the following is my Model class. public class Request { public int Id { get; set; } public string Name { get; set; } [Required] public Gender Gender { get; set; } } And my controller function (POST) public class Values1Controller : ApiController { public IHttpActionResult Post([FromBody] Models.Request request) { if (!ModelState.IsValid) { return BadRequest(); } var gender = request.Gender; var id = request.Id; var name = request.Name; // do some operations!

Many to many MVC 5 Model first write to join table

落花浮王杯 提交于 2020-01-03 05:48:07
问题 I have a "partial" working code with many to many relationship between Teams and Players (and junction table TeamPlayers). The drop down menu on Team and Player side does not work.Though data is stored in db (Player and Team tables)BUT NOT to junction table TeamPlayers. I want to have the possibility in my view for current players and current teams to be connected, aka, save a current TeamId to TeamId in my junction table (and PlayerId to PlayerId). The last insert step is....i´m totally

Jquery ajax call wont access the controller: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

99封情书 提交于 2020-01-03 05:46:08
问题 I keep getting Failed to load resource: the server responded with a status of 500 (Internal Server Error) indicating that the call to my controller method isnt working and I dont know why: var user = "founder"; var clanName = "superClan"; var SuspensionDate = Date.now; $.ajax({ url: '@Url.Action("SuspendUserFromClan", "ChatMethods")', type: "POST", contentType: "application/json; charset=utf-8", data: { 'ClanName': clanName, 'UserToSuspend': userToAdd, 'DateSuspendedTill': SuspensionDate },

Mocking Session not working in MVC 5

廉价感情. 提交于 2020-01-03 05:23:06
问题 I'm storing values in the Session in my controller Action being tested. I've read several articles on how to mock a session and I'm trying to implement Milox's answer to Setting the httpcontext current session in unit test. But when I drill into Locals | this | base | HttpContext Sessions is still null and the test fails with a Null Reference exception when setting the Session variable HttpContext.Session["BsAcId"] = vM.BusAcnt.Id; This is working production code. vM.BusAcnt.Id returns a

Mocking Session not working in MVC 5

你。 提交于 2020-01-03 05:23:02
问题 I'm storing values in the Session in my controller Action being tested. I've read several articles on how to mock a session and I'm trying to implement Milox's answer to Setting the httpcontext current session in unit test. But when I drill into Locals | this | base | HttpContext Sessions is still null and the test fails with a Null Reference exception when setting the Session variable HttpContext.Session["BsAcId"] = vM.BusAcnt.Id; This is working production code. vM.BusAcnt.Id returns a

ASP.NET Identity doesn't load any claims

冷暖自知 提交于 2020-01-03 04:38:11
问题 I have a ASP MVC 5 site using the new identity framework with 3rd party authentication using entity framework as it comes out of the box. I have a logged in user and they have 3 claims (the standard name nameidentifier and authentication provider that seem to be provided by the default ClaimsIdentityFactory). When a user performs some operation I then add a claim for them using this: userManager.AddClaim(userId, new Claim(claimType,claimValue)); If I look in the db in the AspNetUserClaims

ASP.NET Boilerplate MVC 5.x template fails to start

≯℡__Kan透↙ 提交于 2020-01-03 04:24:30
问题 After downloading ASP.NET MVC 5.x template, I update the connection string, restore NuGet packages and then try to run Update-Database command in Package Manager Console, but I consistently get the following error: Could not load file or assembly 'Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) I was able to solve

find UpdateModel Fail Reason

折月煮酒 提交于 2020-01-03 03:04:16
问题 In a create view page, all jquery validation pass, when the create object got passed into action, the UpdateModel fails. Is there anyway that I can find which field explicitly fail the update? By watching "e" in Debug Mode? try { UpdateModel(house_info); } catch (Exception e) { throw e; } 回答1: You can inspect ModelState for errors. The following will give you the list of each property that has an error and the first error associated with the property var errors = ModelState.Keys.Where(k =>