asp.net-mvc-5

What is the difference between using AuthorizeAttribute or IAuthorizationFilter?

南楼画角 提交于 2019-12-05 03:43:06
AuthorizeAttribute requires you to override the OnAuthorization method and IAuthorizationFilter requires you to implement an OnAuthorization method. Seems like the same thing to me, are there any other differences? Why would one be used over the other? EDIT: To clarify, I'm trying to understand what the difference is between the following 2 pieces of code. public class PasswordExpirationCheckAttribute : AuthorizeAttribute { private int _maxPasswordAgeInDays; public PasswordExpirationCheckAttribute(int maxPasswordAgeInDays) { _maxPasswordAgeInDays = maxPasswordAgeInDays; } public override void

ASP.NET MVC tries to load older version of Owin assembly

偶尔善良 提交于 2019-12-05 03:32:23
As a bit of context, I'm developing an ASP.NET MVC 5 application that uses OAuth-based authentication via Microsoft's OWIN implementation, for Facebook and Google only at this stage. Currently (as of v3.0.0, git-commit 4932c2f), the FacebookAuthenticationOptions and GoogleOAuth2AuthenticationOptions don't provide any property to force Facebook nor Google respectively to reauthenticate users (via appending the appropriate query string parameters) when signing in. Initially, I set out to override the following classes: FacebookAuthenticationOptions GoogleOAuth2AuthenticationOptions

SignalR authentication with javascript client

不羁岁月 提交于 2019-12-05 03:23:56
问题 I was playing with the open authentication in MVC5 and SignalR . I use a javascript client to call a simple server method on SignalR and receive a reply from Server. It works well, but if I add the [Authorize] tag, it does not even call the server method (did not get any response while debugging). My assumption was the server will use the Authentication mechanism to challenge the client. Am I missing anything? Do I have to manually authenticate the user from the client side and if so how do I

MVC DropDownList selected value not working

人盡茶涼 提交于 2019-12-05 03:06:06
I am using MVC 5. I have my ViewBag for list as ViewBag.TitleList = new SelectList((new string[] { "Mr", "Miss", "Ms", "Mrs" }), contact.Title); //contact.Title has selected value. then I tried converting the array to SelectListItem ( to no avail) On the View it looks like @Html.DropDownListFor(model => model.Title, ViewBag.TitleList as SelectList, "Select") also I tried @Html.DropDownList("Title", ViewBag.TitleList as SelectList, "Select") The list loads successfully but the Selected Value is Not selected . How to Fix this problem? Update The culprit was ViewBag.Title matching my model.Title.

Why do I need a ToList() to avoid disposed context errors?

送分小仙女□ 提交于 2019-12-05 03:05:36
I'm writing some code to access a database using EntityFrameWork. The code is: public IEnumerable<Rows> GetRows(int id) { using (var context = new ApplicationDbContext()) { var repository = new EntityFrameWorkRepository<int, RowEntity>(context); //need a ToList() here to prevent disposed dbcontext errors return repository.GetRowsFromDb(id).ToList(); } } GetRowsFromDb() uses LINQ to query the database and filter the results using id. I originally wrote the above method without the ToList() call, but when I tried to access objects in the IEnumerable which was returned, I would get an exception

MVC 5, Identity 2.0 Android Rest/Json Api

99封情书 提交于 2019-12-05 02:59:33
问题 I have an ASP.NET MVC 5 Application which uses Identity 2.0 for authentication/authorisation. Now I want to provide access to the data in my web application to my Android Application via Web Api 2.0. My question is: How to control authorize/authenticate the access of my android application? On Android side I use "org.springframework.web.client.RestTemplate" and add this HTTP header to my request: HttpAuthentication authHeader = new HttpBasicAuthentication("username", "password"); HttpHeaders

Web Api FromBody is null from web client

妖精的绣舞 提交于 2019-12-05 02:20:30
Hello I would like to call Web Api method from C# client by my body variable in web api controller is null all the time. How to set it correct ? client side: IFileService imgService = new ImageServiceBll(); var image = System.Drawing.Image.FromFile(serverFile); var dataImage = imgService.ImageToBase64(image, System.Drawing.Imaging.ImageFormat.Png); using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://site.local/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // HTTP POST

MVC Complex model binding with inheritance, nested viewModels and partial views

自古美人都是妖i 提交于 2019-12-05 02:15:23
问题 I don't manage to get the values of my nested models back to the controller, they are all nulls. Here is the simplified architecture: //The viewModel being passed to the view public class RunnerIndexViewModel { public RegisterViewModel User { get; set; } public TrainerViewModel TrainerVM { get; set; } public RunnerBase Runner { get; set; } [Display(Name = "AddContact", ResourceType = typeof(MyRessources))] public bool AddContact { get; set; } } public class RegisterViewModel { // various

Extending IdentityRole and IdentityUser

此生再无相见时 提交于 2019-12-05 01:53:58
问题 I am using ASPNet Identity to implement security in my web application. There is a requirements where in, I need to extend the IdentityRole and IdentityUser. Here is my code to extend the IdentityUser. public class ApplicationUser : IdentityUser { public virtual User User { get; set; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("name=CoreContext") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

Angular model binding with MVC Html.TextBoxFOr

依然范特西╮ 提交于 2019-12-05 01:46:34
问题 I have controls that are model tied to ASP.net MVC5 @Html.TextBoxFor(model => model.OriginLocation.City, new { @class = "form-control", data_ng_model = "address1.City", test_change = "" }) So when the page loads the value of text box input is bound and should display value coming from service with Razor bound controls, latter i can manipulate that value which changes angular model for this control. What i have is textbox loads empty. I can see the value when I view source but its not