asp.net-mvc-5.2

Access ExpireTimeSpan property of Owin Cookie Authentication to notify user of login expiry

▼魔方 西西 提交于 2019-12-03 20:54:21
问题 I am using Owin's cookie authentication to logout users after a time period of inactivity. The thing is, I need to let the user know that their session expires in 'X' minutes. How can I access the authentication cookie to get the time remaining? Is this even possible? Has anybody had to do something like this before? 回答1: It is possible. One way to do that would be to use the OnValidateIdentity callback, which is called every time the cookie is authenticated, which is every time a request is

how to use enum with DescriptionAttribute in asp.net mvc

廉价感情. 提交于 2019-12-03 05:26:51
I am new to asp.net MVC. I am trying to use dropdown control on my view page, which populates from enum. I also want to add custom descriptions to dropdown values. I searched so many examples, but no one posted how to populated description on view page. Here is my code: ViewModel: public enum SearchBy { [Description("SID/PID")] SID = 1, [Description("Name")] Name, [Description("Birth Date")] DOB, [Description("Cause#")] Cause } Index.cshtml <div class="form-horizontal"> @Html.ValidationSummary(true, "", new { @class = "text-danger" }) <div class="form-group form-inline"> @Html.LabelFor(model =

Add column to aspnetusers with database first

余生长醉 提交于 2019-12-01 18:06:33
I have found many tutorials for adding columns to the Identity tables (which I have successfully moved to the application database) with database migrations however my understanding is this is not applicable in database fist projects. So...how do I add columns to the aspnetusers table in a database first project? I would like to ad a bit type column called Is RegComplete which is initially set to 0 then at some point when the user has completed some more tasks then set to 1. OK, I've cracked it! Firstly I didn't realise that although I have moved the Identity tables to the Application database

ReactJS.NET MVC tutorial doesn't work?

◇◆丶佛笑我妖孽 提交于 2019-12-01 05:17:44
I'm trying to setup a new project in Visual Studio that is going to be MVC 5 with a single page app written in ReactJS. So I followed the guide on the ReactJS website . I got to the very first part where you run the project, and I got a syntax error because of the JSX (the browser seemed to want to interpret it as vanilla JavaScript which makes perfect sense). So I added type="text/jsx" to the script tag. In total, my HTML/JSX looks like this: HTML output by Razor view <!doctype html> <html> <head> <title>Hello React</title> </head> <body> <div id="content"></div> <script src="http://fb.me

Razor Syntax gives errors in View before compiling (No intellisense)

◇◆丶佛笑我妖孽 提交于 2019-12-01 03:44:57
I was going through the list of NuGet Packages and I was updating everything things like bootstrap, jQuery, etc. but while I was doing that, I unthinkingly updated Microsoft.Owin and another package (might have been EF or something else) and it was a major version update...woops. I had to jump through hoops by deleting my project, getting an older version from source control and getting everything back to the right versions. Everything is back to normal and I have one last issue. Razor Syntax. When I open up any of my views...anywhere in the project, I get this: Notice how anything using Razor

ReactJS.NET MVC tutorial doesn't work?

我怕爱的太早我们不能终老 提交于 2019-12-01 01:34:11
问题 I'm trying to setup a new project in Visual Studio that is going to be MVC 5 with a single page app written in ReactJS. So I followed the guide on the ReactJS website. I got to the very first part where you run the project, and I got a syntax error because of the JSX (the browser seemed to want to interpret it as vanilla JavaScript which makes perfect sense). So I added type="text/jsx" to the script tag. In total, my HTML/JSX looks like this: HTML output by Razor view <!doctype html> <html>

Razor Syntax gives errors in View before compiling (No intellisense)

為{幸葍}努か 提交于 2019-12-01 00:48:46
问题 I was going through the list of NuGet Packages and I was updating everything things like bootstrap, jQuery, etc. but while I was doing that, I unthinkingly updated Microsoft.Owin and another package (might have been EF or something else) and it was a major version update...woops. I had to jump through hoops by deleting my project, getting an older version from source control and getting everything back to the right versions. Everything is back to normal and I have one last issue. Razor Syntax

Generate a return Url with a custom AuthorizeAttribute

泪湿孤枕 提交于 2019-11-30 22:14:13
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 { controller = "Login", action = "Login" })); } else { base.HandleUnauthorizedRequest(filterContext); } } } ..

Access ExpireTimeSpan property of Owin Cookie Authentication to notify user of login expiry

左心房为你撑大大i 提交于 2019-11-30 21:05:31
I am using Owin's cookie authentication to logout users after a time period of inactivity. The thing is, I need to let the user know that their session expires in 'X' minutes. How can I access the authentication cookie to get the time remaining? Is this even possible? Has anybody had to do something like this before? It is possible. One way to do that would be to use the OnValidateIdentity callback, which is called every time the cookie is authenticated, which is every time a request is made to the web app (assuming active mode). var options = new CookieAuthenticationOptions { // usual options

MVC Remote Validation With Additional bool Fields

风流意气都作罢 提交于 2019-11-30 09:40:32
问题 I am trying to use Remote Validation with an additional bool checkbox field [Remote("IsStorageConnectionValid", "TenantManagement", AdditionalFields = "CreateStorage")] public String StorageConnectionString { get; set; } Validation code public JsonResult IsStorageConnectionValid(string storageConnectionString, bool createStorage){ It works perfectly in terms of it hitting the validator. However createStorage is always true irrespective of the value of the checkbox. If I use additional fields