asp.net-mvc-5

Is there a way to create a custom User and Role without specifying the TKey on IdenitityUser, IdentityRole, and IdentityDbContext?

☆樱花仙子☆ 提交于 2019-12-01 11:29:54
Is there a way to create a custom User and Role without specifying the TKey string in IdentityUser , IdentityRole , and IdentityDbContext ? I ask because it seems to think I don't want the auto-generated primary key Id anymore and I absolutely do. Doing what I've done below, UserManager.Create(user, password) will fail with an EntityValidationError on Id . public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { [Required] [StringLength(50)] public string FirstName { get; set; } [Required] [StringLength(50)] public string LastName {

OnValidateIdentity disables the MVC OWIN remember me option

六眼飞鱼酱① 提交于 2019-12-01 11:24:15
When I activate the OWIN logout-everywhere feature via security stamps and use the OnValidateIdentity -Callback of the CookieAuthenticationProvider with the SecurityStampValidator -class, the user is logged out every time he closes the browser. provider.OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<MyUserManager, MyUser>( System.TimeSpan.FromSeconds(10),(manager, user) => { return user.GenerateUserIdentityAsync(manager); }); However, when I do the plumbing myself (lookup and comparison of the security stamps, rejecting or renewing the identity) in the OnValidateIdentity

Automatically refresh ASP.NET Output Cache on expiry

99封情书 提交于 2019-12-01 11:11:56
I have a few expensive pages that I cache using ASP.NET output cache like so, [OutputCache(Duration=3600, VaryByParam = "none")] Obviously, the cache will expire after 3600 seconds (1 hour), and the next poor guy that happens to load that page will have to wait for the cache to be refreshed from the dabatase. My question is, how do I make the cache to be refreshed immediately on expiry? So that the next guy who happens to visit the page when the cache had just expired will not have to wait for the cache to be refreshed and instead is served with a new cache? Update: I need the cache to be

Mixing Azure AD authentication with Forms authentication

不羁的心 提交于 2019-12-01 10:59:07
I've got an existing MVC5 application that uses Forms authentication. Half of my users are internal employees that also exist in Azure AD. I'd like to give them the option to authenticate against AD but I don't want the other half to have to go through AD. All of the examples I've seen of using Azure AD authentication seems like an all or nothing thing. Can't I just add a button to my login form for the AD users to go to the Azure login and get redirected back with a token? My other option is if they are an Azure user, take their email/password from my login form and try to connect to AD with

Error while generating view in Visual Studio 2019

╄→尐↘猪︶ㄣ 提交于 2019-12-01 09:57:28
问题 While I am creating an ASP.NET MVC view in Visual Studio 2019, I am getting this error: There was an error running the selected code generator: 'the value -1 is outside the acceptable range 0,2147483647 How can I solve it? 回答1: We have to open vs-2019 and select tool -> Options-> General -> ignore GPU memory access exception if the data written didn't change. Mark it as checked then error will be disappear. 回答2: I ran into the same problem tomorrow, tried many manipulations found on different

Response Permanent Redirect in MVC not issuing 301 or changing URL

只谈情不闲聊 提交于 2019-12-01 09:54:30
问题 I am converting an old ASP.NET web forms site to ASP.NET MVC 5. I would like to issue permanent redirects for the old page URLs. Here is what I have done - RouteConfig.cs: routes.MapRoute("About_old", "About/About.aspx", new { controller = "Home", action = "About_old" }); HomeController.cs: public ActionResult About_old() { return new RedirectResult("/About", true); // I've also tried // return RedirectToActionPermanent("About"); // return RedirectPermanent("/About"); } All attempts load the

Mixing Azure AD authentication with Forms authentication

╄→尐↘猪︶ㄣ 提交于 2019-12-01 09:53:35
问题 I've got an existing MVC5 application that uses Forms authentication. Half of my users are internal employees that also exist in Azure AD. I'd like to give them the option to authenticate against AD but I don't want the other half to have to go through AD. All of the examples I've seen of using Azure AD authentication seems like an all or nothing thing. Can't I just add a button to my login form for the AD users to go to the Azure login and get redirected back with a token? My other option is

MVc 5 - validation german date with unobtrusiv js - a simple approach

蓝咒 提交于 2019-12-01 09:50:31
问题 The question: How get the unobtrusiv validation of a german date running in MVC? Because I can't find a running example of using globalize 1.x with MVC 5 to validate a german date I needed two days to get it running. The problems are the order of the js-files, getting the cldr-data and putting it all together in an way it can be reused. In the answer I will show my current solution. 回答1: In this zip-file (https://www.dropbox.com/sh/75dx6alck7itwia/AABFkcgOQVc1bUXFE_jYfR_da?dl=0) you find all

Wait for form.submit() / POST to complete

半城伤御伤魂 提交于 2019-12-01 09:43:24
I'm stuck in a really bizarre situation here. It's complicated to explain but I'll try my best. Detailed explanation of the issue: On every top Nav click (Green donuts/circles), or next button, I must submit the form, if it exists and is valid. If not valid, form.valid() triggers validation errors and return false would stop any further propagation. This setup was working flawlessly until I noticed a strange behavior which isn't very persistence. Form on my 3rd tab, specifically, is quite data heavy. When I hit next button it should practically go thru the same process: check for an existing

MVC5 using MvcSiteMapProvider to build twitter bootstrap menu

僤鯓⒐⒋嵵緔 提交于 2019-12-01 09:38:32
Default menu section in MVC5 template looking like that: <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li>@Html.ActionLink("Home", "Index", "Home")</li> <li>@Html.ActionLink("About", "About", "Home")</li> <li>@Html.ActionLink("Contact", "Contact", "Home")</li> </ul> @Html.Partial("_LoginPartial") </div> _LoginPartial looking like that: @using Microsoft.AspNet.Identity @if (Request.IsAuthenticated) { using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) { @Html.AntiForgeryToken() <ul class="nav navbar-nav navbar