asp.net-mvc-5

MVC 5 Identity Automatic Logout

岁酱吖の 提交于 2019-12-03 04:14:34
问题 How do I implement an Automatic Logout Timer. So basically if the user is inactive for x minutes their session is ended? I have tried: <system.web> <sessionState timeout="1"/> </system.web> But it doesn't seem to work. Here is code that is in my startup: public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes

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

…衆ロ難τιáo~ 提交于 2019-12-03 03:55:52
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 is already authenticated and automatically logs in using the .Aspnet.Applicationcookie and my language

How to pass information from OnAuthenticated event to a controller and SignIn?

北城余情 提交于 2019-12-03 03:55:36
As I've found out here , I can't call HttpContext.GetOwinContext().Authentication.SignIn(...) in FacebookAuthenticationProvider OnAuthenticated event. It seems to be a different context. My users will be from Facebook, which means that I will need to retrieve data such as id , email ... This information is accessible on the OnAuthenticated event and I need this information to SignIn. I need to access this information on my controller... I tried this in the event: context.OwinContext.Set("FacebookUser", rawUserObjectFromFacebookAsJson); But on the controller if I try to retrieve this, it is

What is the best practice for Enterprise level application architecture using MVC5?

此生再无相见时 提交于 2019-12-03 03:51:36
问题 I was wondering what is the best practice for enterprise level architecture based on MVC5. I mean selection between multiple layer or multiple project in one solution? and or maybe more than one solution? any good example project? 回答1: Since my question has been visited a lot in the last year and there is no solid answer as I am aware of that, I decided to provide a comprehensive answer as much as possible. This answer is based on some actual projects experience and with few expert

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

不想你离开。 提交于 2019-12-03 03:46:31
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; filterContext.HttpContext.Response.Clear(); filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

Routing in ASP NET Web API - For different versions of an API

一曲冷凌霜 提交于 2019-12-03 03:27:00
I am reading about Attribute Routing in Web API 2 from here The article says, Here are some other patterns that attribute routing makes easy. API versioning In this example, “/api/v1/products” would be routed to a different controller than “/api/v2/products”. /api/v1/products /api/v2/products How come? EDIT: I would do this in Normal Routing: public static class WebApiConfig { public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/v2/products", defaults: new { controller = V2_Products } ); config.Routes.MapHttpRoute( name:

Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper'

三世轮回 提交于 2019-12-03 03:25:44
问题 I'm using Visual Studio 2015 Community edition, and I've created an ASP.NET MVC 5 project. When I open a view ( Index of Home or any other), it shows first three lines of the page underlined with red as a syntax issue. Here is the error: Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value 'Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor'. Error: Object reference not set to an instance of an object

Gzip compression not working ASP.net MVC5

风流意气都作罢 提交于 2019-12-03 03:22:08
I want to compress my web application with Gzip and I am using following class compression filter public class CompressFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { HttpRequestBase request = filterContext.HttpContext.Request; string acceptEncoding = request.Headers["Accept-Encoding"]; if (string.IsNullOrEmpty(acceptEncoding)) return; acceptEncoding = acceptEncoding.ToUpperInvariant(); HttpResponseBase response = filterContext.HttpContext.Response; if (acceptEncoding.Contains("GZIP")) { response.AppendHeader("Content-encoding",

Migrating to Asp.Net Identity 2.0: new columns not being created in AspNetUsers table

为君一笑 提交于 2019-12-03 03:15:57
I get the following error when I try to register a new user, using Identity 2.0 and the default MVC 5 application: Invalid column name 'Email'. Invalid column name 'EmailConfirmed'. Invalid column name 'PhoneNumber'. Invalid column name 'PhoneNumberConfirmed'. Invalid column name 'TwoFactorEnabled'. Invalid column name 'LockoutEndDateUtc'. Invalid column name 'LockoutEnabled'. Invalid column name 'AccessFailedCount'. (repeats 2 more times, I have a total of 4 test users in AspNetUsers table.) I have a small application I've just upgraded from MVC4/Identity 1.0 to MVC5/Identity 2.0, so I had

One to many relationship between AspNetUsers (Identity) and a custom table

蹲街弑〆低调 提交于 2019-12-03 03:09:46
I'm desperate trying to create an One to Many relationship between AspNetUsers table of Identity 2.0 and a custom table called Map (One user can have many maps, but a map can only have one user) I've tryied mostly every solutions available in this website and also lost many days trying other soulutions found in the web. I'm stuck. Nothing seems to work for me. I'm new to MVC and EF so basically I think I need some sort of step-by-step guide. Can anyone please be very kind to provide me a newbie guide to achieve this from a fresh made MVC5 Project. Thanks and sorry for the redundad question I