asp.net-mvc-5

Display mvc partial view with errors on parent page

不问归期 提交于 2019-12-03 15:37:55
I have a page with multiple forms, each as a partial. I want to post each partial on submit. If there are errors, I want the validation errors to show in the partial as part of the main page i.e. I don't want to just see the partial on it's own page if there are errors. Am I correct in saying this behavior is only possible with an ajax post? How would I return the model state errors WITHOUT an ajax post, just a normal form post? Edit: Still seeing the partial on it's own page Partial - @using (Html.BeginForm("Login", "Account", FormMethod.Post, new { id = "LoginForm" })) { @Html

Extending IdentityRole and IdentityUser

廉价感情. 提交于 2019-12-03 15:27:21
I am using ASPNet Identity to implement security in my web application. There is a requirements where in, I need to extend the IdentityRole and IdentityUser. Here is my code to extend the IdentityUser. public class ApplicationUser : IdentityUser { public virtual User User { get; set; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("name=CoreContext") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>() .ToTable("AspNetUsers");

Asp.Net MVC5 How to ensure that a cookie exists?

限于喜欢 提交于 2019-12-03 15:04:30
问题 I'm new to MVC (5). In order to add localization support to my website I added a " Language " field to my ApplicationUser : IdentityUser What's the best approach to now store this information in the browser and ensure that it gets re-created even if the user manually deletes it? TL; but I've got time What I've tried until now: I started creating a cookie in my method private async Task SignInAsync(ApplicationUser user, bool isPersistent) but I notice that: This method is not used if the user

How to pass error message to error view in MVC 5?

南楼画角 提交于 2019-12-03 14:47:04
问题 I am working on exception handling and have written below code for the same. Web.Config <customErrors mode="On"></customErrors> Code Changes public class CustomExceptionFilter : HandleErrorAttribute { public override void OnException(ExceptionContext filterContext) { //_logger.Error("Uncaught exception", filterContext.Exception); ViewResult view = new ViewResult(); view.ViewName = "Error"; filterContext.Result = view; // Prepare the response code. filterContext.ExceptionHandled = true;

OWIN with LDAP Authentication

ぃ、小莉子 提交于 2019-12-03 14:46:45
Here is my scenario. I have an MVC 5 application that uses Owin as an authentication mechanism. The default template calls the SignInManager.PasswordSignInAsync in the Login action which I would like to overwrite to use LDAP to validate the user instead of looking into the database. I am able to do the validation via: PrincipalContext dc = new PrincipalContext(ContextType.Domain, "domain.com", "DC=domain,DC=com", "user_name", "password"); bool authenticated = dc.ValidateCredentials(userName, password); Then I can retrieve the UserPrincipal using: UserPrincipal user = UserPrincipal

How to inspect MVC response stream using OWIN middleware component?

笑着哭i 提交于 2019-12-03 14:29:20
This question has been asked before in a few forms but I cannot get any of the answers to work, I'm losing my hair and unsure if the problem is just that the solutions were from 2 years ago and things have changed. How can I safely intercept the Response stream in a custom Owin Middleware - I based my code on this, it looks like it should work, but it doesn't OWIN OnSendingHeaders Callback - Reading Response Body - seems to be a different OWIN version, because method signature doesn't work What I want to do is write an OMC that can inspect the response stream from MVC. What I did (amongst

Could not load file or assembly 'WebMatrix.Data`

不打扰是莪最后的温柔 提交于 2019-12-03 14:26:13
问题 I updated MVC4 to MVC5. When you run the application I got an error that I don't have WebMatrix.Data . I installed it PM> Install-Package WebMatrix.Data . Now when you start getting in the browser: Could not load file or assembly 'WebMatrix.Data, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. Located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Anyone know how to fix this?

ASP .Net MVC 5 JsonResult caching

↘锁芯ラ 提交于 2019-12-03 14:08:12
can someone explain me how to implement caching of JsonResult actions in MVC 5 application? I want to use caching of some ajax -called actions using [OutputCache()] attribute. Some of these actions return ActionResult with html -content, some JsonResult with serialized lists of {Id, Title} pairs which I'm going to use to construct dropdown lists. My goal is to reduce amount of DB-queries (while building ViewModels) and server requests (when using ajax-calls for it). So, my code looks like snippets below: [OutputCache(Duration=60*60*24)] public async Task<ActionResult> SearchCaseOrgDialog(){ /

Setting up Forms Authentication for multiple Web Apps in MVC 5 based on OWIN

吃可爱长大的小学妹 提交于 2019-12-03 13:43:07
问题 I am in process of setting up my 1st MVC Web App. I know I need to provide a Forms Based Authentication model as well as I know I will be reusing it for multiple other internal web apps as well. All the documentation for MVC 5 Authentication, which I believe is all based on OWIN stuff, have it "baked" into a single web app using EF Code First no less. What I am trying is to have an another Web App that I strip everything out of except for the Account stuff and then try to "point" my web apps

No valid key mapping found for securityToken

纵然是瞬间 提交于 2019-12-03 13:35:49
I am developing test application for displaying claims of authenticated identity in MVC-ASP.net (Visual studio 2013) I have given authentication from active directory in following way. 1.Add new mvc project in solution . 2.click on Change authentication. 3.select organization account 4.select on premises. 5.given federation url 6.App Id url After running the application i am getting following error. WIF10201: No valid key mapping found for securityToken: 'System.IdentityModel.Tokens.X509SecurityToken' and issuer: ' http://websso.avanade.com/adfs/services/trust ' This error is coming only for