asp.net-mvc-2

How to set a Default Route (To an Area) in MVC

邮差的信 提交于 2019-11-26 11:03:48
Ok this has been asked before but there is no solid solution out there. So for purpose of myself and others who may find this useful. In MVC2 (ASP.NET) I want it so when someone navigates to the website, there is a default area specified. So navigating to my site should send you to ControllerX ActionY in AreaZ. Using the following route in the Global.asax routes.MapRoute( "Area", "", new { area = "AreaZ", controller = "ControllerX ", action = "ActionY " } ); Now this works as in it does try to serve the correct page. However MVC proceeds to look for the View in the root of the site and not in

Best practice for ASP.NET MVC resource files

家住魔仙堡 提交于 2019-11-26 10:33:02
问题 What are the best usage of the following resource files. Properties → Resources (Phil used this resource for localization in DataAnnotation) App_GlobalResources folder App_LocalResources folder I also would like to know what is the difference between (1) and (2) in asp.net mvc application. 回答1: You should avoid App_GlobalResources and App_LocalResources . Like Craig mentioned, there are problems with App_GlobalResources / App_LocalResources because you can't access them outside of the ASP.NET

ASP.NET MVC Html.DropDownList populated by Ajax call to controller?

半城伤御伤魂 提交于 2019-11-26 10:28:38
问题 I wanted to create an editor template for a field type that is represented as a dropdownlist. In the definition of the editor template I would like to populate the DropDownList using a call to an action on the controller returning the results as JSON - Any ideas how to do this? E.g something like: <%@ Control Language=\"C#\" Inherits=\"System.Web.Mvc.ViewUserControl<TheFieldType>\" %> <%= Html.DropDownList(..... 回答1: In the editor template provide an empty dropdown: <%= Html.DropDownListFor(

how to gzip content in asp.net MVC?

对着背影说爱祢 提交于 2019-11-26 10:23:38
问题 how to compress the output send by an asp.net mvc application?? 回答1: Here's what i use (as of this monent in time): using System.IO.Compression; public class CompressAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var encodingsAccepted = filterContext.HttpContext.Request.Headers["Accept-Encoding"]; if (string.IsNullOrEmpty(encodingsAccepted)) return; encodingsAccepted = encodingsAccepted.ToLowerInvariant(); var response =

How to implement proper HTTP error handling in .NET MVC 2?

只愿长相守 提交于 2019-11-26 10:18:03
问题 I\'ve been struggling all day to implement error handling in my ASP.NET MVC 2 app. I\'ve looked at a variety of techniques, but none work properly. I\'m using MVC2 and .NET 4.0 (started the project before MVC3 was released; we\'ll upgrade after we deliver our initial release). At this point, I\'ll be happy to properly handle 404 and 500 errors -- 403 (authorization required) would be great, too, followed by various other specific responses. Right now, I either get all 404s, all 500s, all 302s

ASP.NET MVC - Authenticate users against Active Directory, but require username and password to be inputted

房东的猫 提交于 2019-11-26 10:08:11
问题 I\'m developing a MVC3 application that will require a user to be authenticated against an AD. I know that there is the option in MVC3 to create an Intranet Application that automatically authenticates a user against an AD, but it uses Windows Authentication and automatically logs them on. This application may be accessed on \'Open\' workstations where the user will need to enter their Domain Username and Password. Any examples or online tutorial would be great. An example project would be

ASP.NET MVC: Route with optional parameter, but if supplied, must match \d+

我的未来我决定 提交于 2019-11-26 09:58:20
问题 I\'m trying to write a route with a nullable int in it. It should be possible to go to both /profile/ but also /profile/\\d+ . routes.MapRoute(\"ProfileDetails\", \"profile/{userId}\", new {controller = \"Profile\", action = \"Details\", userId = UrlParameter.Optional}, new {userId = @\"\\d+\"}); As you can see, I say that userId is optional but also that it should match the regular expression \\d+ . This does not work and I see why. But how would I construct a route that matches just

What are the Web.Debug.config and Web.Release.Config files for?

天涯浪子 提交于 2019-11-26 09:19:47
问题 I just upgraded to Visual Studio 2010 and MVC 2.0 and I noticed the Web.config has two additional files attached to it? Are these files used to specify debug and release specific settings, so you don\'t clutter up the main Web.config? Does it even make sense to place a connection string in the root Web.config file if I have a local and remote one in the debug and release Web.configs respectively? Thanks! 回答1: It's the new Web.config transformation feature of Visual Studio 2010. More

Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block?

淺唱寂寞╮ 提交于 2019-11-26 08:50:40
问题 A few days back I asked this question: Why does $.getJSON() block the browser? I fire six jQuery async ajax requests at the same controller action pretty much all at once. Each request takes 10 seconds to return. Through debugging and logging requests to the action method I notice that the requests are serialised and never run in parallel. i.e. I see a timeline in my log4net logs like this: 2010-12-13 13:25:06,633 [11164] INFO - Got:1156 2010-12-13 13:25:16,634 [11164] INFO - Returning:1156

What is the difference (if any) between Html.Partial(view, model) and Html.RenderPartial(view,model) in MVC2?

匆匆过客 提交于 2019-11-26 08:45:56
问题 Other than the type it returns and the fact that you call it differently of course <% Html.RenderPartial(...); %> <%= Html.Partial(...) %> If they are different, why would you call one rather than the other one? The definitions: // Type: System.Web.Mvc.Html.RenderPartialExtensions // Assembly: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 // Assembly location: C:\\Program Files (x86)\\Microsoft ASP.NET\\ASP.NET MVC 2\\Assemblies\\System.Web.Mvc.dll using