i have quite big ASP.NET MVC 2 application (multiple areas, each with own routing registration) using routes like this :
/Item/12345/Detail - where 12345 is the ID of the item. The whole application just rely on that numeric IDs. But now there is an requirement (seo stuff) to make URLs look like this :
/Item/item-unique-string-name/Detail
I would love to handle this globally in some high level - for example load numeric ID before route evaluation and "replace" it in route data. But i am not sure what is the right spot for such a hack - custom MvcHandler, custom IRouteHandler, somewhere else ?
Globally i want to find a textbox which is in a gridview such that i can use that variable in any of the events.
Is that possible in .cs file or if not how can we retreive the variable of a textbox in to a function after finding the textbox using javascript in .aspx page .I tried to find a control in .cs file but I couldn't get it.
Now If I put the above code in try catch block, then "data" variable is not accessible outside try block. How I can declare "data" variable globally and then can collect result in it in try block?
The default behavior of a [WebMethod] attributed static method on an aspx page is to return the error to the caller. We are accessing these methods using json, and the only way we have found of capturing exceptions is either a try/catch in every webmethod on the site or using a javascript callback with the error (which has the unacceptable downside of exposing the error to the client).
Is there any way to globally handle these exceptions using the HealthMonitoring setup in ASP.NET?
We have a large ASP.NET MVC project where all numbers output to the screen are formatted as currency (i.e. ToString("c"). However, negative numbers are showing up with ()'s. For example:
decimal d = -8.88m; Console.WriteLine(d.ToString("c")); //outputs $(8.88)
This is a bit annoying to our users, particularly since there are in textboxes. We have a few thousand places where we send currency fields to the screen like this, so we'd love a way to change the formatting globally. Is there one? All the methods I've seen indicate that you have to create a new formatter, similar to this:
We'd prefer not to change all of our ToString("c") methods ... is there a better way? My first thought was to just change our locale to Australia, but realized the date formatting would be screwed up.
i have this problem where Microsoft actually got the month names wrong for the Greenlandic culture (kl-GL). I also know that i can pass my own array of string to the DateTimeFormatInfo.MonthNames Property, but it seems like the values i specify is only used in the scope of that one CultureInfo instance. Is there a way to tell .Net that every time i have an instance of the kl-GL culture these specific monthnames should be used?
I know that you can create user specific cultures, but i don't have access to some legacy code to actually change the code to use a my own userspecified culture.
Was looking at asp.net mvc complex routing for tree path as an example of how to define a custom route handler for my MVC app. Essentially, I want to give the end user ultimate flexibility in defining the URL for any given page, so I provide them with a field in the interface to specify their own custom URL.
My custom route handler is basically a wild-card handler. It will do a lookup and if it finds a match, map it accordingly. However, if no match is found, I want it to fall back and find the next rule that matches in the global.asax. Is that possible? Or do I essentially need to code the mappings that used to exist in my global.asax into my custom route handler?
I've got a sitemap in db with all current url, but some urls has changed so I added a column for old urls so I can redirect if old urls are requested and redirect to the new url.
I'm localising a site via a Change Language control in the master page. I need to render the control with the current url you're on in each of the different languages.
So if you're on http://site.com/en/Home/About and you change the language to french, I need to direct you to http://site.com/fr/Home/About.
The localisation code works on the route data language property, so I've been trying to figure out how I can:
Get access to the current action (with all original parameters) Get the url to the current action (with all original parameters) with the route data changed.
I've tried passing the ViewContext from the parent into the UserControl, which gives me access to the route data but I can't figure out how to get the language routed url from that.
Looking at the asp.net v4 URL Routing it's easy to see how to access routing data from basically anywhere in the app.
Via: Page.RouteData.Values["blah"]
Unfortuantely the Route data always is blank by the time i hit the page on my v 3.5 implementation of routing. I was wondering if there was any way to either pass the route values to the final page so i can use them there - i really don't want additional logic in my handler file and i have loads of Routes and don't want many RouteHandlers.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.