How do I create a ClaimsIdentity object for Asp.NET MVC 5?

Perhaps the following link can help: var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, “Brock”)); claims.Add(new Claim(ClaimTypes.Email, “[email protected]”)); var id = new ClaimsIdentity(claims,DefaultAuthenticationTypes.ApplicationCookie); var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; authenticationManager.SignIn(id);

How does a new ASP.NET MVC 5 application know how to create a database and how does the Account Controller access the database?

1) WHAT’S GOING ON HERE: When you create a new MVC 5 application and choose “Individual User Accounts“, a new ASP.NET Identity Provider is included which uses Entity Framework 6 Code-First. Microsoft has adopted EF-Code-First to make Identity as customizable as possible. When Identity is accessed for the first time, Entity Framework checks to see … Read more

Server Cannot Append Header After HTTP headers have been sent Exception at @Html.AntiForgery

When Response.Redirect(anyUrl) the status code is set to 302, and the header will added to the response : HTTP 1.0 302 Object Moved Location: http://anyurl.com And when ViewResult is executed and razor render the view the Html.AntiForgeryToken() will called, so the helper tries to add the header X-Frame-Options and some cookies to the response, it … Read more

Web API 2 OWIN Bearer Token purpose of cookie?

In the SPA template there are actually two separate authentication mechanisms enabled- cookie authentication and token authentication. This enables authentication of both MVC and Web API controller actions, but requires some additional setup. If you look in the WebApiConfig.Register method you’ll see this line of code: config.SuppressDefaultHostAuthentication(); That tells Web API to ignore cookie authentication, … Read more

Make sure all *.cshtml files are set to be “Content” for Build Action

You could extend the .csproj with a small snippet that will generate a warning when an item in the “None” group has the extension .cshtml. The snippet would be: <Target Name=”EnsureContentOnViews” BeforeTargets=”BeforeBuild”> <ItemGroup> <Filtered Include=”@(None)” Condition=”‘%(Extension)’ == ‘.cshtml'” /> </ItemGroup> <Warning Condition=”‘@(Filtered)’!=”” Code=”CSHTML” File=”$(MSBuildProjectDirectory)\%(Filtered.Identity)” Text=”View is not set to [BuildAction:Content]” /> </Target> If you see … Read more

How to add ASP.NET MVC5 Identity Authentication to existing database

1) If I want to use identity authentication, is there a reason not to use MVC template? Or is there a reason to use empty template? MVC template also provides bootstrap. Identity authentication, MVC template and bootstrap are not really related. If you create new MVC 5 application, AccountController is created for you. You can … Read more

How to create a user and get the newly created ID with ASP.NET Identity

Using the IdentityUser or using a class that inherits from IdentityUser, makes the model having an UserId attribute. Using following code, passing the user to the method, will fill up the Id. var user = model.GetUser(); var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) result = UserManager.AddToRole(user.Id, “User”); The model.GetUser() returns an object of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)