asp.net-mvc-5


How can I limit the serving of a javascript file to only authenticated users?

為{幸葍}努か 提交于 2020-01-29 04:56:06
问题 I have a WebAPI 2 / AngularJS SPA application that uses Identity 2 for authentication. Locally my code stores a token for authentication. I would like to implement functionality that allows my application to request additional javascript for authenticated users after my initial index.html page has been downloaded. Is there a way I can make my server code give out the javascript files to only authenticated and authorized users? Something similar to the way a controller action method returns

How to pass ID to default value of another view

♀尐吖头ヾ 提交于 2020-01-26 03:27:10
问题 I have a list of incidents which can have associated jobs. I Have a separate views for incidents and jobs. From the incident index page I have the following link to create a new job for that incident: @Html.ActionLink("Create","Create", "Job", new { id = item.IncidentID }, null) which takes the incident ID from that field and loads the Job view. I want to pass the ID as a default value for creating a new job, so the job will be assigned the incident ID. I made this controller: public

ASP.NET MVC Custom RoleProvider cannot retrieve roles from database for username

て烟熏妆下的殇ゞ 提交于 2020-01-25 20:15:07
问题 i cant seem to find the right solution for the above issue. I keep getting System.NullReferenceException: Object reference not set to an instance of an object. i followed this guide http://techbrij.com/custom-roleprovider-authorization-asp-net-mvc The error message is from my custom roleprovider from the GetRolesForUser(string username) at line var user = _VisitorService.GetVisitors().FirstOrDefault(u => u.Username == username); The VisitorService works in the Controller but not in the

MVC Routing with no (or a default) action name

。_饼干妹妹 提交于 2020-01-25 09:52:10
问题 Using MVC 5, I am trying to get some friendly controller/action names working through routing. Banging my head against the wall with this. Given this controller: MyController Index(startPage, pageSize) EditAction(itemId) I am using two routes (defined under an inherited AreaRegistration class) context.MapRoute( "MyControllerRoute", "myArea/MyController/{action}/{itemId}", new { controller = "MyController", action = "Index", itemId = UrlParameter.Optional }, new[] {"MySite.Areas.MyArea

swagger error “Uncaught RangeError: Invalid string length” in mvc angularjs mix project

浪尽此生 提交于 2020-01-24 22:42:06
问题 I have a project in mvc5 and anguarjs mix and here I am trying to add swagger I had installed the latest Swashbuckle and tried this API which is working http://localhost:6790/swagger/docs/v1 and I could say that my json is valid and checked on https://editor.swagger.io but when I tied this on http://localhost:6790/swagger/ui/index (view) this shows error Uncaught RangeError: Invalid string length at JSON.stringify (<anonymous>) at t.exports.u.getModelSampleJSON (swagger-ui-min-js:formatted

Performance considerations with nested declarative @helpers in Razor

余生长醉 提交于 2020-01-24 10:06:29
问题 @helpers, along with partial views allow for great composability, however I would like to know if there is a significant performance cost to be aware. For example: App_Code\Wrappers.cshtml: @helper HeaderWrapper(WebViewPage view, Func<object, HelperResult> content,Func<object, HelperResult> navbar = null) { <div class="container-fluid"> @content(null) </div> if (navbar != null) { <div class="container-fluid"> <nav id="navbar-page" class="navbar-default navbar-collapse collapse" role=

How do I set the WWW-Authentication header in an IAuthenticationFilter implementation?

社会主义新天地 提交于 2020-01-24 04:11:25
问题 I'm implementing basic authentication using MVC5's IAuthenticationFilter interface. My understanding is that this is now the preferred approach instead of using a DelegatingHandler. I've got it working but the www-authenticate header is not being returned in the response. This is my implementation of ChallengeAsync: public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) { var result = await context.Result.ExecuteAsync

Pass selected DropDown value to the controller

大兔子大兔子 提交于 2020-01-23 12:30:30
问题 I have a DropDownList and a button on my View. On click of a button, I want to pass the selected DropDown value to the controller. How to do this? View code is as below: @model Sample2.Models.LeaveType @{ ViewBag.Title = "Status of Application"; } @{ List<SelectListItem> listItems = new List<SelectListItem>(); listItems.Add(new SelectListItem { Text = "All", Value = "A", Selected = true }); listItems.Add(new SelectListItem { Text = "Recommended", Value = "R" }); listItems.Add(new

Request Client Certificate

女生的网名这么多〃 提交于 2020-01-23 12:09:35
问题 I've seen a lot of unsolved questions about this. Apparently many developers have gotten past this issue, but I haven't seen any solutions posted. I'm trying to read a smart card (X.509 CAC) for my ASP.NET MVC 5 web app. When I try to pull the certificate information like this: var request = HttpContext.Request; var cert = request.ClientCertificate; The cert has empty values. The problem appears to be I am not presenting the dialog to request user certificate info like I see on other websites

How to render ModelMetadata object using Html.Displar in Razor-engine in ASP.NET MVC app?

南笙酒味 提交于 2020-01-23 10:50:47
问题 I am trying to utilize the DisplayTemplates feature in razor-engine to automate rendering my display views. I scan my Model to find the correct ModelMetadata for each property that I want to display. But I am not able to render the properties using Html.DisplayFor correctly. I tried to display my property like so // First I find the ModelMetadata for the property // I call this statement in a loop and each iteration I pass a different PropertyName to get the correct model ModelMetadata

工具导航Map