asp.net-mvc-5.2

How to intercept a Url to dynamically change the routing

社会主义新天地 提交于 2020-01-05 08:11:32
问题 I am looking to do something like: For categories where the Controller will be CategoryController www.mysite.com/some-category www.mysite.com/some-category/sub-category www.mysite.com/some-category/sub-category/another //This could go on .. The problem is that: www.mysite.com/some-product needs to point to a ProductController . Normally this would map to the same controller. So, how can I intercept the routing so I can check if the parameter is a Category or Product and route accordingly. I

How to get access token from httpcontext using owin and Mvc 5

▼魔方 西西 提交于 2020-01-03 10:48:41
问题 I've got a IDP implemented in IdentityServer 4. My web app client(implemented in Mvc 5) authenticates with the IDP but now I need to get the access token from the request. A way to do that in .Net Core is to use the Microsoft.AspNetCore.Authentication.AuthenticationTokenExtensions like so: HttpContext.Authentication.GetTokenAsync("acccess_token") I would like to be able to do the same in my .net Mvc5 web app client but I can't find any nuget package or namespace that has a similar

Execute multiple controller actions in one call with MVC.Net 5

十年热恋 提交于 2019-12-24 10:59:08
问题 We have recently upgraded our code base from .Net 4.0 to .Net 4.5.1 and from MVC 2.0 to MVC 5.2.2. We have a custom method in our base controller class which allowed us to update multiple parts of our views within a single request. Since upgrading, this no longer works. Original Code: protected void IncludeAction(string actionName, string controllerName, object routeValues) { //Get Url RouteValueDictionary routes = null; if (routeValues != null) routes = new RouteValueDictionary(routeValues);

Checkbox checked value lost if !ModelState.IsValid

对着背影说爱祢 提交于 2019-12-24 09:57:46
问题 My approach here may be entirely wrong, but I'm slowly learning MVC... I have a form whereby a user must select a number of (or no) modules, based on this model: public class MyProductModule { public string ModuleName { get; set; } public bool Checked { get; set; } } public class ProductRequest { public ProductRequest() { Modules = LoadModules(); } public static List<MyProductModule> LoadModules() { return new List<MyProductModule>() { new MyProductModule() { ModuleName = "Module One",

PerRequestLifetimeManager can only be used in the context of an HTTP request

廉价感情. 提交于 2019-12-19 15:41:03
问题 I have a MVC application that uses Unity as its IoC container and have multiple services defined in my application using the PerRequestLifetimeManager . container.RegisterType<IFileService, FileService>(); Everything works fine, except when I tried to roll my solution to automate tasks (like SharePoint TimerJobs), started in various intervals. For that, I've defined a ServiceLocator -Type class ContainerManager in a separate project, that does essentially this: public static object Resolve

Generate a return Url with a custom AuthorizeAttribute

♀尐吖头ヾ 提交于 2019-12-19 03:42:16
问题 I have a custom authorize attribute: using System; using System.Web.Mvc; using System.Web.Routing; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] public class MyAuthorizeAttribute : AuthorizeAttribute { protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (!filterContext.HttpContext.Request.IsAuthenticated) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new {

Custom 404 Page not showing when StatusCode is not 200

微笑、不失礼 提交于 2019-12-13 15:11:11
问题 In my web.config file I have custom errors enabled: <customErrors mode="On" defaultRedirect="~/Error"> <error redirect="~/Error/NotFound" statusCode="404" /> </customErrors> My NotFound action: public ActionResult NotFound() { Response.StatusCode = 404; //no issues when this is not set return View(); } The problem: This configuration works fine on a local server, but when I move it to a remote server custom 404 pages are not shown (IIS default 404 is displayed) unless the status code of

how to call web api or other restful web services in c#

让人想犯罪 __ 提交于 2019-12-13 09:45:51
问题 I can call every webApi methods by ajax request but I can't do it by c#. this is a simple web api which every body can create it in asp.net mvc web api but I can't find any example about call and get it programmatically by c#. public class TestController : ApiController { // GET: api/Test public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } } please some body say me how can I call this web api method in c# and get these 2 values. how can we get value from a web

Capturing login event so I can cache other user information

半腔热情 提交于 2019-12-12 10:44:16
问题 I've built a web application. When I built it I ticked 'Organizational Accounts' It works well - I log in with my Office 365 account and User.Identity.Name contains the email address This application is a replacement front end for an older ASP Classic app. The App has an existing security table that I need to use. I want to use the email address to look up a record in this table to get The internal database key for the user (so I can use it in database calls) The security level (authorisation

Input mask MVC unmask in controller

杀马特。学长 韩版系。学妹 提交于 2019-12-12 05:27:31
问题 Im working in MVC 5.2 .NET 4.5 : Can anyone point me to a js or other library / method for an input mask that will unmask and just send the entered data in the view model to the controller? Any .js library I've tried so far that can unmask, still sends the mask to the controller. Thank you. 回答1: https://github.com/RobinHerbots/jquery.inputmask Set autoUnmask to true for client side validation and removeMaskOnSubmit to true to get the input with the literals removed in the server side