asp.net-mvc-5

Unable to add and fetch custom claims values

狂风中的少年 提交于 2019-12-01 02:33:25
I am using mvc 5 with identity 2.0. I want use custom claim values over the application but I get null value. What am I doing wrong? Updated code Login Code in account controller if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var result = SignInManager.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout: false); //Generate verification token Dictionary<string, string> acceccToken = null; if (SignInStatus.Success == 0) { var userDeatails = FindUser(model

ASP MVC Authorize Error

笑着哭i 提交于 2019-12-01 01:54:27
问题 When I Use : [Authorize] public ActionResult Index() { .... return View(); } OR [Authorize(Users="john")] public ActionResult Index() { .... return View(); } My Script Working Well But When I Use : [Authorize(Roles="Admin")] public ActionResult Index() { ..... return View(); } Error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is

Farther extending ApplicationUser class in ASP.NET MVC5 Identity system

∥☆過路亽.° 提交于 2019-12-01 01:37:19
问题 I'm creating a simple application for university where a student can make some type of request which is then processed by an employee of particular speciality. I would like to use default MVC5 identity system and to extend the ApplicationUser class using TPH pattern. So I added the common properties to the ApplicationUser: public class ApplicationUser : IdentityUser { [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } [Required] public string

Social Login of facebook not working in ASP.Net MVC 5 project

天涯浪子 提交于 2019-12-01 01:25:15
I am going through a tutorial to implement facebook social log in my sample web site. Below are the steps I did. Pointed my localhost application to https and allowed fake SSL in VS. Created a web app in facebook developer web site and noted down the secret key and id. Added my application localhost URL in the URL section of the dashboard in facebook I added key and id in the starup.Auth.cs file in my ASP.Net MVC-5 project . Behavour: Now when I run my application from local host (https) and click Register then I see the facebook sign in button . Also when I click that button a facebook pop up

IdentityRole in multi-tenant application

青春壹個敷衍的年華 提交于 2019-12-01 01:08:16
I am building an ASP.NET MVC 5 multi-tenant solution and have a slight problem when it comes to roles. I have created a custom role entity as follows: public class ApplicationRole : IdentityRole, ITenantEntity { public ApplicationRole() : base() { } public ApplicationRole(string roleName) : base(roleName) { } public int? TenantId { get; set; } } And done everything else needed.. it's all working nicely, except for one thing...; when a tenant admin tries to add a new role and if that role's name is already being used by a role created by another tenant, he will get the following error: Name

ExternalLoginConfirmation returns null after facebook successful login

主宰稳场 提交于 2019-12-01 01:07:23
Implementing Facebook login in MVC 5 template, had added the app Id and secret code. Initially login was failing as it was returning null public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { // Crashes on this line var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (loginInfo == null) { return RedirectToAction("Login"); } } After searching came across a solution which says to replace existing ExternalLoginCallback method with this [AllowAnonymous] public async Task<ActionResult> ExternalLoginCallback(string returnUrl) { var result = await

Data Annotations / Validation not working for partial views

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 00:54:53
I have some partial views loaded at runtime, based on user input. $("#Categories").change(function () { $.ajax({ url: "/Product/Create" + $("#Categories option:selected").text().replace(/\s+/, ""), type: "Get" }).done(function (partialViewResult) { $("#partialDiv").html(partialViewResult); }); }); The POCO's that are used in the view model are decorated with data annotations, but they are not triggered. The partial views each contain a form (Html.BeginForm()). I guess I'm doing something wrong, but not sure what. Any advice greatly appreciated. Just Include JS files i.e Jquery Unobtrusive js

ASPX Page Response.Redirect to MVC View

断了今生、忘了曾经 提交于 2019-12-01 00:31:52
Is it possible to Response.Redirect in aspx that returns a view from MVC? I have an login.aspx page that i need upon successful login to redirect to a view in ~/Views/Home/index.cshtml is this possible? I've tried to following but the url couldnt be resolved. tried: Response.Redirect("~/Views/Home/Index.cshtml"); Response.Redirect("Home"); The controller is "HomeController" and the view is "Index.cshtml" any help with how to call a controller and view or atleast just the url would help. How about Response.Redirect("/Home/Index"); - that is of course presuming that you have a HomeController

Many to Many relationship in Asp.Net MVC 5 with Identity table and Custom table

*爱你&永不变心* 提交于 2019-12-01 00:18:23
I'm trying to make a relationship between the Users from the table generated by Asp.Net Identity with my own table. The relationship must be many to many, since many Users can work on the same Task (which is my table), and same time an User can work on multiple Tasks. public class Task { public int ID { get; set; } public string Name { get; set; } public string UserID { get; set; } public virtual ICollection<ApplicationUser> Users { get; set; } } public class ApplicationUser : IdentityUser { public int TaskID { get; set; } public virtual ICollection<Task> Tasks{ get; set; } // rest of the code

Passing Model data from View to Controller and using its values

北城以北 提交于 2019-12-01 00:03:10
I'm trying to send data from the view and use it in the controller to construct a filename for an upload file feature I am working on, my code is below. Controller // GET: File [Authorize(Roles = "Admin, Lecturer")] public ActionResult Index() { foreach (string upload in Request.Files) { if (Request.Files[upload].FileName != "") { string path = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/uploads/"; string filename = Path.GetFileName(Request.Files[upload].FileName); Request.Files[upload].SaveAs(Path.Combine(path, filename)); } } return View(); } Model public class UploadModel { [Required