asp.net-mvc-2

How can I change a route value then redirect to that route?

ぃ、小莉子 提交于 2019-12-23 20:13:12
问题 I have a UserAccountController that takes routes like this "/{username}/{action}" . I'd like to create some functionality so that I can take a user to an account-specific page without knowing their username up front. I'd like to be able to use the URL "/your/{action}" which would catch the fact that "your" was sent as their username, get their real username (because they are logged in), and redirect them to "/their-actual-username/{action}". I could do this in each of the controller actions,

What is the correct way to precompile an ASP.Net MVC 2 application?

我们两清 提交于 2019-12-23 19:27:03
问题 What is the correct way to precompile an ASP.Net MVC 2 application from Visual Studio 2010? I am using asp.net 3.5, and trying to use the post build event. I am using this; C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(ProjectDir)" but it gives me an invalid path error on the ProjectDir. UPDATE: I changed "$(ProjectDir)" to $(ProjectDir)\ and it now gives me this error; "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond

How can I accept email address as a route value?

帅比萌擦擦* 提交于 2019-12-23 18:53:27
问题 How can I have this simple Route: http://domain.com/Calendar/Unsubscribe/my@email.com I have a route that looks like: routes.MapRoute( "Unsubscribe", "Calendar/Unsubscribe/{subscriber}", new { controller = "Calendar", action = "Unsubscribe", subscriber = "" } ); and my action is: public ActionResult Unsubscribe(string subscriber) { ... } Without any parameters, like http://domain.com/Calendar/Unsubscribe/ works fine, but soon I add the email, I get a 404 page :( Is there any trick I have to

Should one try to guard against null reference exceptions / index out of bounds exceptions in MVC views?

旧巷老猫 提交于 2019-12-23 18:01:22
问题 I want to post a comment to this question's accepted answer, " Haven't views abandoned code behind now? So what are you going to test? " pointing out that it seems to me as soon as you add an <% if (Model.Thing == "abc") {} %> or @if (Model.Thing == "abc") {} to your view, there exists the potential for something to blow up, and that potential should be guarded against. In regard to the question I linked to, I could see an argument being made that one should guard against the possibility of

Windows Shared hosting - custom scheduled task

☆樱花仙子☆ 提交于 2019-12-23 15:58:44
问题 I have a windows shared hosting and i need to run some scheduled c# executable every day for create sitemap, send newsletter,etc... The provider tell me that i can't run executable for security reason. Whay can i do? The provider suggest me to buy a VPS, but do not think it makes sense to spend more money just to run some scheduled task. Does exists an alternative way? 回答1: Implement your once-a-day task in an asp.net page on your shared server. Then set-up a process, on a machine that you do

How to handle UnauthorizedRequest via Ajax call in Asp.net MVC2

痴心易碎 提交于 2019-12-23 15:53:35
问题 Brief: I have a sub classed AuthorizeAttribute in my framework in which I am doing custom authorization. I am in the process of switching from normal asp.net mvc view rendering to Ajax rendering via jQuery. Hence every link in the application does a ajax call to get the data. In order to cater for this I have converted most of my pages to partial views so that each ajax request only gets the portion that needs to be updated on the page. During the normal view rendering when a request was

ASP.NET MVC2 Master Page - Server side script not rendering, first bracket being escaped

六月ゝ 毕业季﹏ 提交于 2019-12-23 13:07:15
问题 I have a master page which I am using as a template to allow me to define meta tags per page. My master page takes in a model which contains the meta information, here is an example of what I am trying to do the following: <meta name="description" content="<%= Model.description %>" /> <meta name="keywords" content="<%= Model.keywords %>" /> However, when I check the HTML once the page is rendered I get this: <meta name="description" content="<= Model.description %>" /> <meta name="keywords"

ASP.NET MVC strongly typed view compilation error

微笑、不失礼 提交于 2019-12-23 12:58:56
问题 This is a strange one. I changed something (not sure what) and now my app's view doesn't compile at runtime. The view itself is strongly typed: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyNamespace.OperatorModel>" %> When I visit the page, it fails to compile, saying: CS1061: 'object' does not contain a definition for 'Log' and no extension method 'Log' accepting a first argument of type 'object' could be found (are you missing a

Windows Azure - Worker role - detect environment

一个人想着一个人 提交于 2019-12-23 12:57:23
问题 Anyone know of a way to determine if a worker role is running in the production or staging environment? My worker role sends out daily email summaries of activities but if I have code in staging the email gets duplicated because I have two workers running. Thoughts? 回答1: RoleEnvironment static class is available to find out current deploymentId. Using current deploymentId you can query the Diagnostics Management API to find out the type of a deployment 0 or 1. I believe "0" is production and

How to get only Date from datetime column using linq

女生的网名这么多〃 提交于 2019-12-23 12:37:21
问题 I have a column in the database as EffectiveDate which is the type of DateTime. I have a linq query to get EffectiveDate from the table. but when I get I am getting EffectiveDate with time. But in my linq query i need only Date I dont want the time for EffectiveDate. how to write the Linq query for that? Thanks 回答1: Call the Date property on any DateTime struct EffectiveDate.Date; or call EffectiveDate.ToShortDateString(); or use the "d" format when calling ToString() more DateTime formats