asp.net-mvc-5

Web API 2 Attribute Routing Controller Selection

给你一囗甜甜゛ 提交于 2019-12-13 06:27:01
问题 I use Web API 2 Attribute Routing in my project to provide JSON interface over my data. I am facing weird behaviour of controller selection, not decided yet whether it's a bug or a feature :) Let me describe my approach. I would like to simulate OData syntax with help of attribute routing (direct OData usage has been refused due to design principles). For example, to get entity with id=5 I use HTTP GET request to URI http://mydomain.com/api/Entity(5) . I expect to use the same URI with HTTP

ASP.net mvc ActionResult parameter

China☆狼群 提交于 2019-12-13 06:25:28
问题 My controller looks like this: public ActionResult Index(string username) { if (string.IsNullOrEmpty(username)) { _userId = User.Identity.GetUserId(); } else { var user = UserService.GetUserByUserName(username); if (user != null) { _userId = user.Id; } else { return RedirectToAction("Index", "Routines"); } } return View(); } [HttpGet] public JsonResult GetUserHomeData() { return Json(CreateHomeViewModel(), JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult GetUserStatisticsOverview(

Use attribute routing parameters for other attributes

荒凉一梦 提交于 2019-12-13 06:08:00
问题 I use Attribute Routing (MVC) to call Controller Methods and also an Authorizationattribute with custom Properties: [Route("{id:int}")] [UserAuth(ProjectId=3)] public ActionResult Select(int id) { return JsonGet(Magic.DoSomethingMagic()); } UserAuth is just a simple AuthorizationAttribute: public class UserAuthAttribute:AuthorizeAttribute { public int ProjectId { get;set;} protected override bool AuthorizeCore(HttpContextBase contextBase) { var currentProject=new Project(ProjectId); return

How to use Roles with Integrated Windows Authentication

北城以北 提交于 2019-12-13 05:54:58
问题 I'm working on a Web Application implemented in ASP.NET MVC 5 with Web API 2. I've implemented Integrated Windows Authentication by adding the following code to web.config: <system.web> <authentication mode="Windows" /> </system.web> <system.webServer> <security> <authentication> <windowsAuthentication enabled="true"/> </authentication> </security> </system.webServer> and by adding [Authorize] annotation on top of my controllers. Now, I'm asked to give access to some functionality based on

ASP.NET MVC 5: Custom Authentication

谁说我不能喝 提交于 2019-12-13 05:51:59
问题 In my ASP.NET MVC 5 application I need to use custom Authentication. Basically a custom library on which I call a method and which returns an object that contains information about the user. I've created a new MVC 5 application and selected the "No Authentication" option. Then I've added an Http Module which currently looks like this: private void Context_AuthenticateRequest(object sender, EventArgs e) { // Make the call to authenticate. // This returns an object with user information.

ASP.NET Display Templates - No output

南笙酒味 提交于 2019-12-13 05:18:46
问题 I have this model: public class DefinitionListModel : List<DefinitionListItemModel> { } Then I have this display template (partial view) setup for it in DisplayTemplates: @model Company.Product.Models.DefinitionListModel <dl> @foreach (var definition in Model) { Html.DisplayFor(m => definition); } </dl> Which calls this default display template because each item is a DefinitionListItemModel : @model Company.Product.Models.DefinitionListItemModel @Html.DisplayFor(m => m.Term, "DefinitionTerm")

Aspnet unexpected logout

谁都会走 提交于 2019-12-13 04:59:59
问题 I'm working in a project where we are using aspnet mvc 5 and we have some problems with a unexpected logout after 5 min of inactivity in a page. I have this in my web.config: <sessionState timeout="30"/> <authentication mode="None"/> What you think are causing this about project? If need more information ask please. Thanks. PS: My AuthenticationType is ApplicationCookie PS2: Added machine key to web.config and still logout after a couple of minutes: <machineKey validationKey="string"

Adding A New MVC 5 Controller with Views Using Entity Framework Scaffolding Error

浪子不回头ぞ 提交于 2019-12-13 04:51:18
问题 When I try to add a MVC 5 controller with views using entity framework in my web app project, as it attempts to scaffold, I am getting this error: "There was an error running the selected code generator: 'There was an error getting the type (name of entity model here).' Try rebuilding the project." I did previously switch from MVC 4 to MVC 5, which perhaps could be at the root of this error. Any help is appreciated, thanks. 回答1: Times when I've encountered something similar, I've been able to

Async page load in mvc

风格不统一 提交于 2019-12-13 04:42:29
问题 Im mvc application,there is a some view, data of some portion in view is taking time at the server end, so I need to load the other part of the view first and when the process completes the remaining portion will load. For this I have create a partial view the partial view action is async and returns a task. But in Mvc 5 I cant use await keyword in view. I sesrch for that mvc 6 is fix this issue. So now I am loading the partial view by using ajax call. But can I do without ajax call. Or with

IDX10503: Signature validation failed after updating to Owin.Security v 4.0.0

江枫思渺然 提交于 2019-12-13 04:13:58
问题 As per subject, I updated the Owin.Security.WsFederation and dependent packages to version 4.0 and I get the error. I did not make any code changes other than changing using Microsoft.IdentityModel.Protocols; to using Microsoft.IdentityModel.Protocols.WsFederation; where is the WsFederationConfiguration class seems to be now. Here is my StartupAuth : public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication( new CookieAuthenticationOptions { AuthenticationType =