asp.net-mvc-5

Load Razor Views From Database in ASP.NET MVC 5

丶灬走出姿态 提交于 2019-12-04 14:48:34
We are trying to develop a corporate CMS application in ASP.NET MVC 5. The user needs to create a new page, change an existing page content or delete a page alltogether from an admin application. Another requirement states that some of the pages can include custom widgets which were written in Razor syntax. These 2 requirements lead me to load razor views from the database. I googled and find a couple of examples. The first one is to extend the VirtualPathProvider and register it with the expression below in the Application_Start method. protected void Application_Start() { ...

date format dd/MM/yyyy not working in asp.net mvc 5

Deadly 提交于 2019-12-04 14:41:06
I'm developing an asp.net mvc 5 application, in which I'm trying to set a validation for dd/MM/yyyy format, I've been struggling a lot to find an appropriate solution but no success, what I want it to accept: 24/01/2016 but it displays validation message as : The field JoiningDate must be a date. Here is what I've tried : [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public DateTime JoiningDate { get; set; } Also, I want it to display the date in dd/MM/yyyy format everywhere at the user's end but this is a second part of my question, firstly, it should at

How to set a custom ClaimsPrincipal in MVC 5?

ε祈祈猫儿з 提交于 2019-12-04 12:52:28
I created a custom principal class public class FacebookPrincipal : ClaimsPrincipal { public JObject Data { get; set; } } And I want to use it. When the user logs in, I tried to set var fbP = new FacebookPrincipal { Data = user.Data }; Thread.CurrentPrincipal = fbP; AuthenticationManager.User = fbP; HttpContext.User = fbP; It works right after I set it, but when I go ho home/index the value is lost var user = HttpContext.GetOwinContext().Authentication.User; var bbbb = this.User; var cccc = ClaimsPrincipal.Current; All the above methods return a Principal of type ClaimsPrincipal and casting to

Role Management in ASP MVC 5 (Microsoft.AspNet.Identity)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 12:42:40
问题 in ASP MVC5 RC I didn't get the role system to work. My database has all needs tables an role exist but proofing if user is in role always return false (no SQL exception or something)!? Did I need to activate role system for IPrincipal somewhere? Test code: AccountController accCont = new AccountController(); // check role exist : result = true var roleExist = await accCont.IdentityManager.Roles.RoleExistsAsync("61c84919-72e2-4114-9520-83a3e5f09de1"); // try find role by name : result = role

Is there a way to determine an ASP.Net MVC Bundle is rendered before or not?

ⅰ亾dé卋堺 提交于 2019-12-04 12:15:44
Here is the situation : On a MVC application I have a partial that is rendering a script bundle . this partial is rendered several times. Is there a built-in way to determine an specific Bundle is rendered before in some place on page ? Thanks professionals Update : here is the code for clearing the condition main layout : <html> <body> @if(someCondition){ @Html.RenderPartial("SamePartial") @Html.RenderPartial("SamePartial") @Html.RenderPartial("SamePartial") } </body> </html> and this is inside partial : <div>Blah Blah Blah</div> @Scripts.Render("~/bundles/JusNeededInsidePartial") @Styles

Facebook MVC 5 ASP.NET Identity - Email is null for certain users

允我心安 提交于 2019-12-04 11:56:06
问题 This is a problem i am trying to solve for a month now. (tried any possible article/code out there). In ExternalLoginCallback action, AuthenticationManager.GetExternalLoginInfoAsync() returns a valid object (with all the provider details) but email is null for certain Facebook users . For the large majority of Facebook login email is presetnt. But for about 30% of logins I get an exception down the process because the email is null. Luckily sometime ago I've created a Facebook user which

bootstrap modal for delete confirmation mvc

雨燕双飞 提交于 2019-12-04 11:47:43
I'm developing an MVC 5 web application. Within one of my Razor Views I have a table which spits outs several rows of data.Beside each row of data is a Delete button. When the user clicks the delete button I want to have the Bootstrap Modal popup and ask the user to confirm their deletion. add line before foreach loop @Html.Hidden("item-to-delete", "", new {@id = "item-to-delete"}) @foreach (var item in Model) { <td> <button type="" class="btn btn-sm blue deleteLead" data-target="#basic" data-toggle="modal" data-id="@item.bookid">delete</button> </td> } 2.and my modal <div class="modal fade"

After upgrade to EF6 - The property cannot be configured as a navigation property

守給你的承諾、 提交于 2019-12-04 11:43:37
I have a following class: [Table("TagSource")] public class TagSource { public TagSource() { this.DataSources = new HashSet<DataSource>(); } [Key] public int TagSourceId { get; set; } ... public bool IsHistorical { get; set; } public Nullable<int> ModifiedEntryId { get; set; } ... public int? AttachedTagSourceId { get; set; } [ForeignKey("AttachedTagSourceId"), InverseProperty("TagSourceId")] public virtual TagSource AttachedTagSource { get; set; } [ForeignKey("ModifiedEntryId"), InverseProperty("TagSourceId")] public virtual TagSource ModifiedEntry { get; set; } } I was using Entity Framework

How to mock ApplicationUserManager from AccountController in MVC5

余生颓废 提交于 2019-12-04 11:33:02
I am trying to write Unit Test for Register Method at AccountController I am using moq and what is the correct way to mock ApplicationUserManager, ApplicationRoleManager and ApplicationSignInManager from Unit Test. public AccountController(ApplicationUserManager userManager, ApplicationRoleManager roleManager, ApplicationSignInManager signInManager) { UserManager = userManager; RoleManager = roleManager; SignInManager = signInManager; } public ApplicationUserManager UserManager { get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set {

Configurable Application Insights Instrumentation Key

旧时模样 提交于 2019-12-04 11:28:48
How can I best make the Application Inisghts' Instrumentation Key configurable in a way that allows an Azure Administrator to manage the settings for an App Services deployment of an MVC5 web application? Is there a certain event in an MVC application initialization where this should be done or is it okay to do it at pretty much any point? I am using the Trace Listener integration as well. By default, the Instrumentation Key (iKey) is set in the ApplicationInsights.config file. Additionally, if you include the JavaScript portions, the iKey is again set in the _Layout.cshtml file. This is two