asp.net-mvc-5

infinite loop going back to authentication page when using OAuth in MVC5

自作多情 提交于 2019-12-04 11:05:51
问题 I have written a webpage that takes advantage of Google/Facebook auth using MVC5 and OAuth sometimes, I'm able to auth very well using either Facebook or Google. It works quite well. However often what happens is Navigate to the login page Choose either google or facebook provide the account info, getting the necessary redirects redirect back to login page, but not logged in I'm not receiving (or not looking in the right place) any errors that clue me in - I am using SSL on Azure for hosting

Min and Max values for EditorFor

泄露秘密 提交于 2019-12-04 11:00:21
I've been trying this code to set minimum and maximum on my EditorFor : <label id="LbStartYear" style="width: 200px">From Date: @Html.EditorFor(model => model.SelectedYearBegin, new { htmlAttributes = new { @min = "0", @max = "20" } })</label> But no success. Minimum and Maximum are never set. I tried removing the quotation from 0 and 20 , also tried with and without the @ . Any ideas? Simply use Range DataAnnotation attribute on your model property. By using this attribute you can restrict user to enter any other number which doesn't fall in the range. Import following namespaces - using

There is already an object named '__MigrationHistory' in the database

廉价感情. 提交于 2019-12-04 10:50:46
When I tried to execute SQLQuery (generated by Update-Database -Verbose -f -Script locally in Visual Studio) on remote database, I saw the following error returned by SQL Server Management Studio: Msg 2714, Level 16, State 6, Line 1 There is already an object named '__MigrationHistory' in the database. How to solve this? __MigrationHistory is an auto-generated table used by EF to track what upgrades/patches it has applied to the database. EF is completely aware of that table and handles it on its own. You should ot create/drop/alter that table. It seems your database already has that table. If

AspNet.Identity Custom User and Custom Role should be simple; what am I missing?

强颜欢笑 提交于 2019-12-04 10:45:18
Using examples from http://www.asp.net/identity I've gotten this far. The RoleManager works flawlessly and I treat the UserManager the same. I think everything is correct, but I can't seem to new up a UserManager correctly in a controller. What is wrong? At one point, I was successfully getting the UserManager to work but was getting an EntityValidationError saying "Id is required" when creating a new user with UserManager.Create(user, password); as posted in this question UserManager.Create(user, password) thowing EntityValidationError saying Id is required? So after some time of hit and miss

Unity 3 Configuration By Convention not finding Types in Web Project

好久不见. 提交于 2019-12-04 10:42:59
I am trying to get this convention configuration working but I am having a problem in my ASP.NET MVC5 Project.. I have added the following in my Application_Start method and hooked it up to DependencyResolver public static IUnityContainer CreateContainer() { IUnityContainer container = new UnityContainer(); container.RegisterTypes( AllClasses.FromAssembliesInBasePath(), WithMappings.FromAllInterfaces, WithName.Default, WithLifetime.ContainerControlled); return container; } But it fails to register any types, on closer inspection, when I see whats in AllClasses.FromAssembliesInBasePath() it

Windows Authentication not working in ASP.NET MVC 5 web app

[亡魂溺海] 提交于 2019-12-04 10:40:42
问题 I have an ASP.NET MVC 5 app and am trying to enable Windows Authentication. The development machine is Windows Server 2008 R2, IIS Express 8.0, Visual Studio 2013 & .NET Framework 4.5. I get a 404 Not Found error when ever I browse the app. The app enters a redirect loop with http://localhost:63455/Account/Login?ReturnUrl=%2F . Eventually the ReturnUrl ends up being very large as it gets appended to with each redirect. My web.config looks like this: <system.web> <authentication mode="Windows"

ASP.NET Identity 2 Remember Me - User Is Being Logged Out

断了今生、忘了曾经 提交于 2019-12-04 10:36:44
问题 I am using Identity 2.1 in my MVC5 app. I am setting the isPersistent property of the PasswordSignInAsync to true to enable 'Remember Me': var result = await SignInManager.PasswordSignInAsync(model.Username, model.Password, true, shouldLockout: false); But if I stay logged in overnight, then when I refresh the page in the morning, it logs me out and I have to sign in again. How do I prevent automatic logging out until the user manually logs out? Is it something to do with the Cookie

Attribute inheriting from AuthorizeAttribute not working

三世轮回 提交于 2019-12-04 10:35:03
I'm currently trying to implement security in a new ASP MVC 5 application, based on user roles. The goal is to prevent users from accessing certain controllers or controller methods if they don't have a certain role (or higher). Based on what I've read on the question so far, I created an attribute that inherits AuthorizeAttribute which looks like this (MyAppRole is an enum, btw) : [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class AuthorizeRoleOrSuperiorAttribute : AuthorizeAttribute { private MyAppRole

“Value cannot be null or empty. Parameter name: contentPath” on a most unexpected line on postback when ModelState has errors

有些话、适合烂在心里 提交于 2019-12-04 09:37:17
It's been two hours straight I have been haggling with this monstrosity. I get this error: Value cannot be null or empty. Parameter name: contentPath On this line in my view: @Html.ValidationMessageFor(model => model.IssueName, "", new { @class = "text-danger" }) The stack trace given below seems to suggest that a call to Url.Content has been made, but I have made no such call. Below is the stack trace and that is followed by some more lines of code around the line which causes the error: [ArgumentException: Value cannot be null or empty. Parameter name: contentPath] System.Web.Mvc.UrlHelper

Gzip compression not working ASP.net MVC5

混江龙づ霸主 提交于 2019-12-04 09:32:53
问题 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