asp.net-mvc-2

Antiforgery token exception only when debugger is run

試著忘記壹切 提交于 2019-12-07 08:02:13
问题 I have an mvc2 app which is serving content through iframes. The iframed page is simply a form. It has a request validation token. Everything works well cross domain until a developer uses the Visual Studio 2005 debugger. As soon as they do, I get the following error details. Exception: System.Web.Mvc.HttpAntiForgeryException : A required anti-forgery token was not supplied or was invalid. Stack Trace: at System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext

iframe good or bad for my MVC web-app scenario

三世轮回 提交于 2019-12-07 07:16:26
I've been working into intranet web solutions which are to be used by a specific set of users of a system - like supply chain management. No SEO or marketing - only easy of use and simplicity that appeals them and makes their task simple. I'm using MVC2 with ASP.Net. I'll explain my scenario in generic terms. I've a page which has a tab view. The first tab loads a record from a master table and the other tabs load data for some details table. And ideal example would be like: Tab 1: Add/Edit Customer (master) record Tab 2: Add/Edit Orders for a Customer Tab 3: Add/Edit Items for an Order

Restrict Area to a given role

此生再无相见时 提交于 2019-12-07 07:05:34
问题 I have an area setup in MVC2, called Admin/ , which I want I only want Users who belong to the role "admins" to have access. I know I can decorate each of the methods with [Authorize(Roles="admins")] , but this seems tedious when your talking about multiple controllers with multiple actions. Is there an better and cleaner way? 回答1: You could define a base controller decorated with this attribute that all controllers in the area derive from. 来源: https://stackoverflow.com/questions/3291385

Ajax Form breaks after adding html5 attributes in Chrome/Safari

我只是一个虾纸丫 提交于 2019-12-07 07:01:07
问题 Step by step description: New Asp.Net MVC2 project Model: public class TestModel { public int Property { get; set; } } HomeController: [HandleError] public class HomeController : Controller { public ActionResult Index() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(TestModel model) { return Content(model.Property.ToString()); } } Index.aspx: <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MVCTest.Models.TestModel>" %> <!DOCTYPE html> <script type="text

ASP.NET MVC: Accessing ViewModel Attributes on the view

时光怂恿深爱的人放手 提交于 2019-12-07 06:58:23
问题 Is there any way to access any attributes (be it data annotation attributes, validation attributes or custom attributes) on ViewModel properties from the view? One of the things I would like to add a little required indicator next to fields whose property has a [Required] attribute. For example if my ViewModel looked like this: public class MyViewModel { [Required] public int MyRequiredField { get; set; } } I would want to do something in the EditorFor template like so: <%@ Control Language=

Call Default Model Binder from a Custom Model Binder?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 05:42:32
问题 I have written a Custom Model Binder which is supposed to map Dates, coming from URL-Strings (GET) according to the current culture (a sidenote here: the default model binder does not consider the current culture if you use GET as http-call...). public class DateTimeModelBinder : IModelBinder { #region IModelBinder Members public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (controllerContext.HttpContext.Request.HttpMethod == "GET") { string

T4MVC and duplicate controller names in different areas

南楼画角 提交于 2019-12-07 05:42:08
问题 In my application I have controller named Snippets both in default area (in application root) and in my area called Manage . I use T4MVC and custom routes, like this: routes.MapRoute( "Feed", "feed/", MVC.Snippets.Rss() ); And I get this error: Multiple types were found that match the controller named 'snippets'. This can happen if the route that services this request ('{controller}/{action}/{id}/') does not specify namespaces to search for a controller that matches the request. If this is

MVC noob - changing part of URL in a link

泪湿孤枕 提交于 2019-12-07 05:21:08
问题 I have a site that supports localization. I would like to be able to switch between english and french. Let say the user is currently at URL: http://www.mysite.com/ en /Home I would like to redirect to: http://www.mysite.com/ fr /Home If the user click on a "French" link how to change the URL part to "fr" yet not change the "Home" part of the URL (basically I want preserve the current location of the user) Hope my question makes sense! I'm probably missing something very basic? EDIT: Kind of

Url.Content on Azure

点点圈 提交于 2019-12-07 03:51:28
I have an ASP.NET MVC 2 application that has page with a link to a pdf file <a href="<%= Url.Content("~/Downloads/test1.pdf") %>">test1</a> Downloads directory is at MVCApplication1/Downloads This works fine locally and on ISS, but returns a page not found when uploaded to Azure. Check the path that is being emitted in the HTML. Its likely relative to the Azure datacenter/cluster, and is meaningless to your client if your client is outside Azure. If you see something like "http://RD1204900029029/Downloads/test1.pdf", thats your issue. You'll need to emit the actual path using application logic

How do I display the duration it took to generate a page in a pages footer?

不羁的心 提交于 2019-12-07 02:56:27
问题 During debug builds I would like to show the duration it took, server side, to generate a page in the pages footer. So for example if a page takes 250ms server side I would like that displayed in the footer, in debug builds. How can I achieve this in an ASP.NET MVC project? 回答1: Add this to the footer in your master page: Page rendering took <%= DateTime.Now.Subtract( this.ViewContext.HttpContext.Timestamp ).TotalMilliseconds.ToString() %> You can also wrap this in an extension method: public