Tag: asp.net mvc 4

如何将Stream上载到Azure Media Services

我们使用ASP.NET MVC 4允许用户通过我们的网站上传video和音频。 我想使用Azure Media Service作为后端。 在遵循Azure的教程时 ,我遇到的问题是Azure Media Services SDK似乎不允许上传原始数据流。 相反,我能找到的唯一上传方法使用路径字符串参数。 我想避免将文件保存到磁盘( 默认情况下它已经流式传输到磁盘 ),并且能够将请求发布的文件直接流式传输到Azure。 到目前为止,这是我的代码: public void SaveMedia(string fileName, System.IO.Stream stream) { CloudMediaContext mediaCloud = new CloudMediaContext(“account”, “key”); AssetCreationOptions assetOptions = new AssetCreationOptions(); var asset = mediaCloud.Assets.Create(fileName, assetOptions); var assetFile = asset.AssetFiles.Create(fileName); var accessPolicy = mediaCloud.AccessPolicies.Create(fileName, TimeSpan.FromDays(3), AccessPermissions.Write | AccessPermissions.List); var locator = mediaCloud.Locators.CreateLocator(LocatorType.Sas, […]

MVC 4区域路由不起作用

我创建了一个空的MVC4应用程序,一切正常,之后我将一个区域添加到我的项目名为“主持人”。 我的区域路由代码是这样的: using System; using System.Web.Mvc; namespace EskimoArt.Areas.Moderator { public class ModeratorAreaRegistration : AreaRegistration { public override string AreaName { get { return “Moderator”; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( “Moderator_default”, “Moderator/{controller}/{action}/{id}”, new {controller=”Dashboard”, action = “Index”, id = UrlParameter.Optional } ); } } } 我的Global.asx代码是这样的: using System.Web.Http; using System.Web.Mvc; using System.Web.Optimization; […]

在MVC / Razor中,如何获取多个复选框的值并将它们全部传递给控制器​​?

我有一个视图,其中包含模型中的项目列表。 我需要为每一行添加一个复选框,让用户选中多个复选框,并将选择了哪一行的标识符传递给控制器​​。 我知道如何通过动作链接传递单个值,但我不确定如何通过动作链接传递多个值或如何“收集”选择哪些行。 我将在下面展示我的一些代码尝试。 有人可以帮我理清为什么我无法获得传递给控制器​​的所有复选框的值吗? 这是我的页面 Checkbox App ID Date Name [] 1 5/10 Bob [] 2 5/10 Ted [] 3 5/11 Alice 我需要用户做的是选择第1行和第3行(例如)并将这些应用程序ID传递给控制器​​。 我开始列出各种尝试,但决定只是展示我当前的尝试,看看是否有人可以指出我做错了什么。 我在网上和我的例子之间看到的主要区别是我使用PagedList并在foreach循环中创建表的行。 当命中控制器时,参数int为空白。 如何从复选框中获取值? 我使用这个站点的基本思想是命名所有复选框,并通过动作链接传递ICollection: http : //haacked.com/archive/2008/10/23/model-binding-to-a-list。 ASPX / 视图: @model PagedList.IPagedList Merchant Application Report @foreach (var item in Model) { @Html.ActionLink(item.ApplicationID.ToString(), “ViewApplication”, new { ID = item.ApplicationID, edit = […]

实体到json错误 – 在序列化类型的对象时检测到循环引用

尝试将实体对象转换为JSON字符串时发生以下错误。 我正在使用C#MVC4代码首先进行数据库设计。 因为FK和表之间的关系会产生这个问题。 解决方法是什么? 序列化System.Data.Entity.DynamicProxies.User类型的对象时检测到循环引用 我的代码是 User ma = db.user.First(x => x.u_id == id); return Json(ma, JsonRequestBehavior.AllowGet);

Unity 3和错误“类型名称或别名”xxxxx“无法解析。 请检查您的配置文件并validation此类型名称。“

有没有办法解决Unity 3的这个问题? 我已经尽一切可能绕过这个消息错误,但我无法解决; 我已经做了我在googles搜索中看到的所有内容。 我几乎放弃并尝试另一种DI解决方案。 我的配置文件: 我的界面: using Biblioteca.Transport; using System.Linq; namespace Biblioteca.Contracts { public interface IManterCategoriaBO { IQueryable GetAll(); CategoriaDTO GetById(int id); void Insert(CategoriaDTO dto); } } 我的具体课程: using Biblioteca.Contracts; using Biblioteca.Transport; using Biblioteca.Data; using System; using System.Linq; namespace Biblioteca.Business { public class ManterCategoriaBO : IManterCategoriaBO { public CategoriaDTO GetById(int id) { CategoriaDTO dto […]

ASP.NET MVC4和Web API身份validation+授权(Windows 8和Web)

我使用Simple Membership db创建了一个ASP.NET MVC 4 Internet Web应用程序,用于存储用户,角色和配置文件。 在我的应用程序中,我创建了一个Web API控制器,它将响应http:// 127.0.0.1/api/users ,此调用将返回存储在db中的所有用户的列表作为JSON 。 UsersController使用[Authorize]属性进行修饰,因此必须对对http:// 127.0.0.1/api/users任何调用进行身份validation。 在主页面上,我有一个按钮,一旦按下jQuery ajax get请求就会执行,并将显示Web API(json)返回的用户列表。 如果我登录并按下按钮,一切正常……检索并显示用户列表。 如果我没有登录,则消息显示为401 – Unauthorized (jquery调用statusCode中的自定义消息),因此它可以正常工作,因为[Authorize]属性。 我的问题:如何在Web API向其发出请求,获取用户列表以及从Windows 8应用程序或Windows Phone 8或Windows Forms中显示这些用户列表时如何进行身份validation? 换句话说,来自Web浏览器以外的客户端?

仅在safari浏览器中ASP.net MVC中的IFrame中的会话为null

页面包含IFrame,只有在Safari的情况下,会话才为空。 我的Safari版本是5.1.7 我正在使用MVC 4.5 Everything在其他浏览器中完美运行。 我使用以下代码.. protected override void OnResultExecuting(ResultExecutingContext filterContext) { base.OnResultExecuting(filterContext); filterContext.HttpContext.Response.AddHeader(“p3p”, “CP=\”CAO PSA OUR\””); GetFirstError(); }

如何使用Ajax Begin表单正确使用部分视图

我在index.cshtml中有以下代码 @using Kendo.Mvc.UI; @using xx.Relacionamiento.Modelo.Bussiness.Entities; @using xx.Relacionamiento.Modelo.Bussiness.Entities.Custom; @model PresupuestosGenerale @{ ViewBag.Title = “Index”; Layout = “~/Views/Shared/_Layout.cshtml”; } @Html.Partial(“CreateOrEditPresupuestoGeneralxx”, Model) 然后我有以下PartialView @using xx.Relacionamiento.Modelo.Bussiness.Entities.Enumeraciones; @using xx.Relacionamiento.Modelo.Bussiness.Entities; @using Kendo.Mvc.UI; @model PresupuestosGenerale @using (Ajax.BeginForm(“CreateOrEditPresupuestoGeneralxx”, new AjaxOptions() { HttpMethod = “Post”, UpdateTargetId = “ContenedorPresupuestoGeneral”, InsertionMode = InsertionMode.Replace })) { @Html.HiddenFor(h => h.PresupuestoGeneralId) @Html.Hidden(“Categoria”,CategoriaEvento.xx.ToString()) Presupuesto Global xx @(Html.Kendo().NumericTextBoxFor(e => e.PresupuestoGlobal) .Decimals(0) […]

MVC 4 Web API寄存器filter

我正在使用MVC 4 Web API为应用程序创建服务层。 我正在尝试创建一个全局filter,它将对API的所有传入请求起作用。 现在我明白这必须配置不同于标准的MVC全局动作filter。 但我遇到的问题是我在网上找到的任何一个例子。 我遇到的问题是使用Web API注册filter。 我的Global.asax设置如下…… public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { AreaRegistration.RegisterAllAreas(); MVCConfig.RegisterRoutes(RouteTable.Routes); MVCConfig.RegisterGlobalFilters(GlobalFilters.Filters); WebApiConfig.RegisterRoutes(GlobalConfiguration.Configuration); WebApiConfig.RegisterGlobalFilters(GlobalConfiguration.Configuration.Filters); } } 我的标准Mvc路由和filter正常工作。 和我的WebApi路由一样。 以下是我对webApifilter注册的内容… public static void RegisterGlobalFilters(System.Web.Http.Filters.HttpFilterCollection filters) { filters.Add(new PerformanceTestFilter()); } 这是PerformanceTestFilter …… public class PerformanceTestFilter : ActionFilterAttribute { private readonly Stopwatch _stopWatch = new Stopwatch(); public […]

MVC 4 – LogOff控制器操作,找不到404

我刚刚结束了一个大学项目,我不确定我是否一直盯着我的电脑太长时间并且遗漏了一些显而易见的东西,但是当我尝试将用户注销时,我得到了404而不是找到URL /帐户/ LogOff。 我有一个导航栏,显示登录/注销,具体取决于用户是,登录还是注销: @if (!Request.IsAuthenticated) { Sign In } else { @Html.ActionLink(“Log Off”, “LogOff”, “Account”) } @Html.Partial(“~/Views/Account/_LoginPartial.cshtml”, new ViewDataDictionary()) 在我的帐户控制器中,Internet模板附带的默认LogOff操作: [HttpPost] [ValidateAntiForgeryToken] public ActionResult LogOff() { WebSecurity.Logout(); return View(“Index”); } 有人能告诉我为什么会发生这种情况 – 在我将笔记本电脑靠在墙上之前。 干杯。