/account/externallogincallback?error=access_denied#_=_
Situation 1: Facebook login is working in local while not in live site.
Solutions
1. Check AppID and Secret are both correct
2. Check with hosting provider if they are not blocking traffic.
Preserving Knowledge
/account/externallogincallback?error=access_denied#_=_
Situation 1: Facebook login is working in local while not in live site.
Solutions
1. Check AppID and Secret are both correct
2. Check with hosting provider if they are not blocking traffic.
//require application to use SSL
filters.Add(new RequireHttpsAttribute());
}
}
After that, we need to update project url. Right click on project > properties > web and update Project Url like https://localhost:44331/
//UserStore & RoleStore
//UserManager, RoleManer and SignInManger
var roleStore = new RoleStore
var roleManager = new RoleManager
roleManager.Create(new IdentityRole("Role1"));
UserManager.AddToRole(user.Id, "Role1");
Note: UserManager.AddToRole(user.Id, "Role1")
will add record to AspNetUserRoles but not the cookie. Later when we check the role using
User.IsInRole("Role1")
The above code will return false because it checks the cookie. We need to re-signin the user to update the cookie
SignInManager.SignIn(user, false, false);
Identity information like roles and claims are stored in the cookie when user logs in.
In App_Start > FilterConfig.cs
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute()); //redirects the user to error page when an actions throws an exception
filters.Add(new AuthorizeAttribute()); //all controllers will require authentication so we don't have to add [Authorize]
}
}
filterContext.HttpContext.Trace.Write("(Logging Filter)Action Executing: ")
Trace can be viewed in http://host:[port]/Trace.axd
Before that we need to add
<system.web>
<trace enabled="true"/>
</system.web>
in web.config
I have a column IsPrivate which was originally tiny int but I decided to change it to bool
PM> add-migration MigrationName results to
AlterColumn("dbo.Jobs", "IsPrivate", c => c.Boolean(nullable: false));
When I run update-database, I got an error
The object 'DF__Jobs__IsPrivate__52E34C9D' is dependent on column 'IsPrivate'.
ALTER TABLE ALTER COLUMN IsPrivate failed because one or more objects access this column.
It’s because IsPrivate column has default constraint DF__Jobs__IsPrivate__52E34C9D so I need to manually add code to drop it
Sql("ALTER TABLE dbo.Jobs DROP CONSTRAINT DF__Jobs__IsPrivate__52E34C9D");
AlterColumn("dbo.Jobs", "IsPrivate", c => c.Boolean(nullable: false));
When I run update-database again, this time it’s successful
Getting in View current controller, action and id in View
string controller = ViewContext.RouteData.Values["controller"].ToString();
string action = ViewContext.RouteData.Values["action"].ToString();
Getting current controller, action and id in Controller
string actionName = this.ControllerContext.RouteData.Values["action"].ToString();
string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
[Key, Column(TypeName = "varchar"), MaxLength(50)]
public string UserId { get; set; }
}
//this is the Key to One-to-One/Zero relationship
HasKey(c => c.UserId);
}
}
In web.config > system.web
modes: On, Off, RemoteOnly
<!--On - display Views/Shared/Error.cshtml only rendered when there is an exception, 404 is not included in this custom error -->
<customErrors mode="RemoteOnly"></customErrors>
This applies whenever the server hits 500 or 404 errors. Not good in debugging but good in production. In system.webServer
<!--errorMode="DetailedLocalOnly" display only to remote clients-->
<!--errorMode="Custom" display to all both local and remote -->
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<remove statusCode="500" subStatusCode="-1" />
<error statusCode="404" path="404.html" responseMode="File" />
<error statusCode="500" path="500.html" responseMode="File" />
</httpErrors>
Note: adding the second block will override the first block
Beside “Debug” there is a dropdown, click and select “Configuration Manager”. In “Active Solution Configuration” select “New” then add a name like “Testing” and “Select copy settings from” preferrably copy settings from Release.
Right click “web.config” and select “Add Config Transform”. This will create Web.Testing.config.