asp.net-mvc-2

Returning http status code 409 Conflict (without ASP.NET MVC alterations)

房东的猫 提交于 2019-12-06 04:27:50
I am trying to return a HTTP response with 409 status code, content type "application/json" and a json data in the content. The problem is that at the client level, response.content returns html result. Somehow ASP.Net MVC has decided to return a html error message instead of what I intended. I've checked at web.config and 409 is not part of the custom error message. I've checked IIS 7.0 Error Pages section as well for 409 and it is not set there. I wonder where I can find the default configuration that manage asp.net mvc http error code mechanism. I am working based on ASP.Net MVC 2.0 and

How to provide ASP.NET MVC2 master pages with a model indepdent of the controller

瘦欲@ 提交于 2019-12-06 04:11:49
I'm using strongly typed views and autofac for Dependency Injection under ASP.NET MVC2 and I'm trying to get a common dynamic header via dependency injection. I.e. i want this to happen without the view having to be away of this content even existing and i was hoping to avoid static discovery of the container and manual resolution, but I can't find a way to easily inject the master or a partial view included in the master via either ctor or property injection. I can't imagine this is an uncommon task, but all I can find in terms of methods is Controller subclassing to stuff data into untyped

When to commit NHibernate transactions in ASP.NET MVC 2 application?

无人久伴 提交于 2019-12-06 04:00:08
问题 First, some background: I'm new to ASP.NET MVC 2 and NHibernate. I'm starting my first application and I want to use NHibernate, because I come from JSP + Struts 1 + Hibernate web applications. No one seems to be talking about this, so I guess it must be pretty obvious. Still I scratch my head because I can't find a solution that accomplish the following things: 1) I want to use the "session per request" strategy. So, everytime a user makes a request, he gets an Nhibernate session, starts a

Find element on site from a fancybox iframe

微笑、不失礼 提交于 2019-12-06 03:36:35
I'm trying to update a element on my site from a fancybox. In the fancybox i do a $.post() and get back html data that i want to populate in a div on my page. I open up a iframe window with html and this script below is in that iframe . It cant find it from the fancybox so anybody got idea or solution on how to reach a element thats not inside the fancybox iframe ? $('.add-to-cart').click(function () { var $this = $(this).closest('form'); $.post($this.attr('action'), { quantity: $this.find('#quantity_id').val() }, function (data) { parent.$.fancybox.close(); $('#container').html(data); },

Is it safe to store only userId using SetAuthCookie() in ASP.NET

你。 提交于 2019-12-06 03:20:52
问题 I was wondering if it was safe to store only UserId (primary key in the database) in the cookie using FormsAuthentication.SetAuthCookie() and saving it as a persisting cookie? I've seen a lot of example where people save usernames but this(userId) could be a one or two digit number which would I guess make it even easier to obtain. So my question is should I do it? If not, why and would it be a lot better if I simply saved the username? (which could again be a short name) 回答1: It is not safe

Can I add MVC 2 DataAnnotation attributes to existing properties?

旧城冷巷雨未停 提交于 2019-12-06 03:14:48
I'm using a generated class as a model, and I wish to add DataAnnotation attributes to some of its properties. As it's a generated code, I don't want to add the annotations directly. Is there another way to attach them to a property? I'd considered making the model an interface, and using a partial class to get the generated class to subscribe to it. Is there a less elaborate solution, assuming that would even work? Yes there is. You have to create metadata class that will have the same properties that your original model, and connect it to your model with MetadataType attribute: [MetadataType

Hashed passwords cannot be retrieved. Either set the password format to different type, or set enablePasswordRetrieval to false

痴心易碎 提交于 2019-12-06 03:06:58
问题 I got some website and now I want to get the passwords. I use it: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="TravelChamps" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> And this error happens: Configured

ASP.NET MVC 2 strongly typed htmlhelper, indexes

纵饮孤独 提交于 2019-12-06 02:55:13
public class Foo { public bool Checked {get;set;}} View: <viewdata model="Foo[] fooList" /> <for each="var f in fooList"> ${Html.CheckBoxFor(x=>x[fIndex].Checked)} </for> Will output: <input id="Checked" name="Checked" type="checkbox" value="true" /> <input name="Checked" type="hidden" value="false" /> <input id="Checked" name="Checked" type="checkbox" value="true" /> <input name="Checked" type="hidden" value="false" /> <input id="Checked" name="Checked" type="checkbox" value="true" /> <input name="Checked" type="hidden" value="false" /> Problem is that System.Web.Mvc.ExpressionHelper

Routing in ASP.NET MVC 2.0

感情迁移 提交于 2019-12-06 02:18:45
I'm looking to make a really simple route in my ASP.NET MVC 2.0 website. I've been googling for help but all the examples I can find are for really complex routing. Basically I want all the pages in my Home Controller to resolve after the domain as opposed to /Home/ For example I want http://www.MyWebsite.com/Home/LandingPage/ To become http://www.MyWebsite.com/LandingPage/ But only for the Home controller, I want the rest of my controllers to function as normal. I thought about creating a controller for each and just using an index, but we need lots of landing pages for our marketing like

Getting the names of previous action and controller in MVC controller

廉价感情. 提交于 2019-12-06 02:13:38
问题 I can get the name of current action and controller like : string controllername = this.ValueProvider.GetValue("controller").RawValue.ToString(); string actionname = this.ValueProvider.GetValue("action").RawValue.ToString(); Also I can get the reffer url by something like : string MyReferrer = Request.UrlReferrer.ToString(); But how can I get the names of previous action and controller in the mvc2 controller? 回答1: This should work! // Home is default controller var controller = (Request