asp.net-mvc-5

VirtualPathProvider in MVC 5

瘦欲@ 提交于 2019-11-30 18:43:21
I can't seem to get a custom VirtualPathProvider working in asp.net MVC 5. The FileExists method returns true but then the GetFile method isn't called. I believe this is because IIS takes over the request and does not let .NET handle it. I have tried setting RAMMFAR and creating a custom handler, as in this solution https://stackoverflow.com/a/12151501/801189 but still no luck. I get a error 404. My Custom Provider: public class DbPathProvider : VirtualPathProvider { public DbPathProvider() : base() { } private static bool IsContentPath(string virtualPath) { var checkPath = VirtualPathUtility

MVC-6 vs MVC-5 BearerAuthentication in Web API

China☆狼群 提交于 2019-11-30 18:10:05
I have a Web API project that use UseJwtBearerAuthentication to my identity server. Config method in startup looks like this: public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseJwtBearerAuthentication(options => { options.AutomaticAuthentication = true; options.Authority = "http://localhost:54540/"; options.Audience = "http://localhost:54540/"; }); // Configure the HTTP request pipeline. app.UseStaticFiles(); // Add MVC to the request pipeline. app.UseMvc(); } This is working, and I want to do the same thing in an MVC5 project. I tried to do something like this:

What is the XsrfKey used for and should I set the XsrfId to something else?

杀马特。学长 韩版系。学妹 提交于 2019-11-30 17:46:20
In my MVC 5 web app I have this (in AccountController.cs): // Used for XSRF protection when adding external sign ins private const string XsrfKey = "XsrfId"; and public string SocialAccountProvider { get; set; } public string RedirectUri { get; set; } public string UserId { get; set; } public override void ExecuteResult(ControllerContext context) { var properties = new AuthenticationProperties { RedirectUri = RedirectUri }; if (UserId != null) { properties.Dictionary[XsrfKey] = UserId; } context.HttpContext.GetOwinContext().Authentication.Challenge(properties, SocialAccountProvider); } How

Scaffolding controllers with repositories in Mvc5, EF6, VisualStudio 2013

二次信任 提交于 2019-11-30 17:41:15
In vs2012 I used to use Steve Sanderson's mvcScaffolding Package with this package I could scaffold Action Methods with unit tests and controllers with repositories and dependency injection. My question is simple. Is there a way to do so in vs2013? When I install the package in vs2013 I get the following errors: Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9 + Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.Cus ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MVC5 hangs on MapSignalR when reconnecting after AppPool cycles

故事扮演 提交于 2019-11-30 17:32:33
I have the following code in my Startup.SignalR.cs: using Microsoft.AspNet.SignalR; using Owin; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Admin { public partial class Startup { public void ConfigureSignalR(IAppBuilder app) { var Config = new HubConfiguration() { EnableDetailedErrors = false, Resolver = new DefaultDependencyResolver() }; #if DEBUG Config.EnableDetailedErrors = true; #endif // Any connection or hub wire up and configuration should go here app.MapSignalR(); GlobalHost.Configuration

How to structure a new ASP MVC app?

こ雲淡風輕ζ 提交于 2019-11-30 17:26:47
问题 I need to start a new mvc project and as always I have issues about asp identity, never know where to put it! I plan to organize solution like this: ProjectWebUI - mvc app with asp identity framework (made from internet template with authentication) ProjectDataAccessLayer - with repository classes that use dapper as database access technology ProjectWebAPI - web service But I have a little confusion and before start coding I need advice from someone more experienced (as until now all my

MVC 5.0 [AllowAnonymous] and the new IAuthenticationFilter

放肆的年华 提交于 2019-11-30 17:20:46
When I create a new asp.net mvc 4.0 application, one of the first thing I do , is create and set a custom authorize global filter like so: //FilterConfig.cs public static void RegisterGlobalFilters(GlobalFilterCollection filters) { //filters.Add(new HandleErrorAttribute()); filters.Add(new CustomAuthorizationAttribute()); } Then I create the CustomAuthorizationAttribute like so: //CustomAuthorizationAttribute.cs protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { if (filterContext.HttpContext.Request.IsAjaxRequest()) { //Handle AJAX requests filterContext

New window opens on click of actionLink

我与影子孤独终老i 提交于 2019-11-30 17:14:01
问题 I have a requirment to invoke a controller method from the view page. On click of the link below the method should be invoked. @Html.ActionLink(item.InvoiceNumber, "SendPdfStatement", "Invoice", new { item.InvoiceNumber }, new { target = "_blank" }) the method signature is as: public void SendPdfStatement(string InvoiceNumber) { InvoiceNumber = InvoiceNumber.Trim(); ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter("InvoiceNumber", InvoiceNumber); List

ASP.NET MVC 5 renders different bool value for hidden input

て烟熏妆下的殇ゞ 提交于 2019-11-30 16:58:11
Given the following viewmodel: public class FooViewModel { public bool IsBoolValue { get; set; } } and this view: <input type="hidden" id="Whatever" data-something="@Model.IsBoolValue" value="@Model.IsBoolValue" /> The output of the hidden input field is this: <input type="hidden" id="Whatever" data-something="True" value="value"> How come the value attribute is not set to True , but the data-something attribute is? Is there a change in MVC 5 that would cause this, since in my MVC 4 apps this problem does not occur. Jason Evans I think I've figured it out. I believe the Razor viewengine is

The type or namespace name 'System' could not be found

帅比萌擦擦* 提交于 2019-11-30 16:50:10
I have the following errors (and more) in all my views (*.cshtml) when opening my project in Visual Studio 2015 Professional. Error CS0246 The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) Severity Code Description Project File Line Error CS0518 Predefined type 'System.Object' is not defined or imported Severity Code Description Project File Line Error CS0518 Predefined type 'System.String' is not defined or imported I got these references: <ItemGroup> <Reference Include="Microsoft.CSharp" /> <Reference Include="Sitecore.Kernel