How To Get Current Route Information In OnActionExecuting

Jun 3, 2010

my urls look like:{languagecode}/{controller}/{action}/{id}
where language code is en-us, etc.
From the OnActionExecuting event, how can I get these values?

View 1 Replies

Similar Messages:

How To Get The Url To The Current Action (after Modifying Some Route Data)

Aug 17, 2010

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 and you change the language to french, I need to direct you to

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.

View 2 Replies

Automatically Add Specific Value From Current Route To All Generated Links?

Feb 20, 2011

I have site culture in URLs like this:


And it works like a charm with a little help from custom MvcHttpHandler that sets current thread's UI culture on every request based on route value. My problem is how do I automatically add the language route value from current request to all outgoing links? E.g. when page /EN/Foo/Bar is requested, I would like this

"example link",
MVC.Home.Index()) %>

To automatically generate the same result as this:

"example link",
this.ViewContext.RouteData.Values["language"]) %>

And of course the same for all other helpers like BeginForm() etc. In my current code base there are already > 1000 occasions where these helpers are used, and requiring .AddRouteValue every time is very fragile as some developer will forget to use it with 100 % certainty. I hope the only solution is not creating custom Html helpers for everything?

View 1 Replies

Modify Form To Only Display Current User Information?

Oct 1, 2010

the current page code below lists profile information of all users within with my site. i'd like to modify it so that it only displays information about the current user logged in.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Security" %>
MembershipUserCollection users;
public void Page_Load()


View 1 Replies

Web Forms :: Using HttpContext.Current.Items To Store Information?

Oct 27, 2010

I was under the impression that you could use the HttpContext.Current.Items collection to pass information between pages but it doesnt seem to workLets say i have a Page1 ButtonClick, the button click handler stores a value in the collection like so; HttpContext.Current.Items("Test1") = "Test"Then i do Response.Redirect("Page2.aspx").In the Form_Load of Page2, HttpContext.Current.Items("Test1") contains nothing. Why does this not work when its all part of the same postback?This would be perfect, because i wouldnt need to worry about clearing the values between requests because they would automatically get cleared each time the page was posted back.

View 5 Replies

Web Forms :: Current Logged In User's Information In Sharepoint List?

Oct 8, 2010

in order to prepopulate some user information, i used query to search the sharepoint list. my question is how to search loggin user's info in the list. i used following testing query function. it works fine. however, it can only search specific text, cannot be changed according different user.


View 1 Replies

AJAX :: Slideshow Extender Retrieve Current Display Picture Information?

Feb 17, 2010

My slideshow extender work perfectly fine, but I want to retrieve the current display picture's information on the server side.

So I added a normal asp button on the same page as the slideshow extender. When button clicked, it fire off a server side function. In the function I grabbed the SlideShow's name label, description label or the Image, but none of them contain any current information of the picture displayed at slideshow extender.

Is there another way to obtain the slideshow extender current state? Or am are those name, description label text value should be updated?

View 1 Replies

All Viewmodels Inherit From 'BaseViewModel', Can Set This Up In OnActionExecuting

Jan 22, 2011

If all my actions have a model that inherits from BaseViewModel, is it possible to initialize this model from the OnActionExecuting method?

Currently in all my actions I do this:

var model = new SomeModel();
model.User = Users.Get(...);

Now I am loading the user object in OnActionExecuting, so I was hoping I could setup my model from there somehow.

View 1 Replies

C# - Redirect In FileAttribute's OnActionExecuting Not Properly Working

Feb 3, 2010

I have an action called EditProfile. To secure it I have added a class RequireUserLogin inherited from ActionFilterAttribute. In the OnActionExecuting, when I redirect user to login page, before going to login page, it first execute the EditProfile action code (which i don't expect) and than redirect the user to login page. I want to not come in action code. Currently the only option I have is throw exception. Is there any other options. The code is:

public class RequireUserLogin : ActionFilterAttribute
public override void OnActionExecuting(ActionExecutingContext filterContext)
if (string.IsNullOrEmpty(userID))

The EditProfile action is:

public ActionResult EditProfile()

View 1 Replies

MVC :: Webforms Route / Implementing Route In Global.asax

Mar 13, 2011

I tried to mix 4 webfrom and ASp.Net MVC 3. I add required lines in webconfig, but I've issues implementing route in global.asax

Currently I use several routes for webfroms. routs template are like below

routes.MapPageRoute("Node", _
"article/sport/{nID}/", _

I encounter error, when I add below lines to global.asax

routes.MapRoute( _
"Defaultss", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = UrlParameter.Optional} _

I want to know how could I mix ASp.Net MVC routes with webforms routes.

View 3 Replies

MVC :: A Route Named 'Admin_default' Is Already In The Route Collection?

Mar 9, 2010

when i run the app i got this error

A route named 'Admin_default' is already in the route collection. Route names must be unique.
Parameter name: name

this is my AdminAreaRegistration


View 2 Replies

MVC :: Controller Base Class Initialize() And OnActionExecuting() Not Called When Unit Testing?

Nov 16, 2010

I'm using a simple base class for my controller that sets a piece of ViewData and makes use of the HttpContext. My understanding is that I need to put this code in Initialize() or OnActionExecuting(). I tried both, but believe Initialize() is what I want.

This works when running the app in VS just fine.

I wrote a unit test that calls the action and checks the ViewData for the expected value. When unit testing, neither method is called.

View 2 Replies

How To Set A Property In Custom Controller Wrapper In OnActionExecuting How To Pass To Site.Master

Jun 3, 2010

Say I have a class that wraps the Controller class:

public class MyController : Controller
public string SomeProperty {get;set;}
public override void OnActionExecuting(...)
SomeProperty = "hello";

Now in my site.master, I want to have access to the SomeProperty that I just set. How can I do this?

View 2 Replies

Route Constraints And Empty Route?

Sep 24, 2010

I have a url that I want to map routing to:


where tabvalue is one of: "personal", "professional", "values" or nothing.

I want to map it to a route like:


But my problem is - I don't know how to specify such constraints. I'm trying this regex:


but it only works when I use url



and doesn't work for


how to specify the correct constraint?

P.S. I'm not using MVC, just WebForms

View 6 Replies

C# - MVC 3 Custom Route Handler - Skip To Next Custom Route Rule?

Mar 14, 2011

Was looking at 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?

View 2 Replies

ADO.NET :: Automatically Loading Information From A MS SQL DB When Information Is Entered

Jan 19, 2011

I am making an online form (literal form) that needs to have a certain function: when the user enters a 5-digit number, the form should automatically query the MS SQL DB and retrieve information associated to that number and populate other form elements (text boxes, etc.) accordingly.

So say the # was 12345 and in the DB, the record matching 12345 has name=Fred. So, when I enter 12345 into the form textbox, the name text box should be automatically populated with Fred in it.

If this is not easily achievable, I guess a submit button beside the 5-digit number text box can do.

I am still learning my way around ASP.NET and Visual Studio 2005, however I have ample experience with HTML, CSS, JavaScript, C/C++. The ASP.NET app is to be written in C#.

View 1 Replies

RenderAction Not Finding Action Method In Current Controller In Current Area?

Mar 15, 2010

I'm creating an ASP.NET MVC 2 (RTM) project that uses areas. The Index action of the Home controller of one area needs to use RenderAction to generate a sub-section of the page. The action called is also defined in the same Home controller. So the call should just be:

<% Html.RenderAction("List") %>

However, I get an exception:A public action method 'List' was not found on controller 'RareBridge.Web.Areas.Events.Controllers.HomeController'.

Note that I'm not in the "Events" area! I'm in a completely different area. If I remove the "Events" home controller, then the exception still occurs but names a different controller (still not the one I want it to call).

I've also tried providing the controller name and area to the RenderAction method, but the same exception occurs. What is going on here?

BTW: I am using Autofac as my IoC container

View 2 Replies

Web Forms :: Find Current URL Of Page During Code Behind Submission (NOT Current Web App URL)

Aug 18, 2010

I am looking for a way to figure out the current URL that the page is currently on (NOT what the page currently is, but where the CODE is at). ie. My web app is located at: [URL] my code is: String page = [URL]

String response = GetResponse(page); //basically the above code goes to the website [URL] and parses the HTML within it and brings it back and populates the variable string "response". But, sometimes the [URL] throws me a curve ball and redirects me to: [URL] I want to be able to use a try/catch to be able to "catch" the error of a different page: ie validateUser.aspx. So, I need to do to this: try

String page = [URL];
String response = GetResponse(page);
//code to check the behind URL to see if [URL] is the URL OR IF [URL] is the current URL

understand I know how to find the URL of the current page the web app is on. I need to find the current page that threw the exception during the execution of the code behind.

View 1 Replies

Access The Current Thread's Context Using HttpContext.Current?

Mar 11, 2010

I have a static class with serveral static methods. In these methods, I'm trying to access the current thread's context using HttpContext.Current. For example:

var userName = HttpContext.Current.User.Identity.Name;

However, when I do that, I receive a NullReferenceException, the infamous "Object reference not set to an instance of an object."

View 3 Replies

Web Forms :: Get Name Of Current Page And Current Subroutine

Oct 17, 2010

I am building in error-logging into my site, and want to be able to get hold of the current page name that the error occurred in, as well as the specific subroutine or function, to then pass to a VB.NET function. Is there anyway to get hold of this information without hard-coding the names manually? For example,

Dim strCurrentPageName = ???
Dim strCurrentRoutine = ???

View 6 Replies

MVC :: How To Add A Certain Route

Apr 5, 2010

I want to do the following:

routes.MapRoute("testwithoutcontroller", "Overview/Index/{year}", new {year = 2010});

But it fails when I call Overview/Index/2010 and gives me this error:

The RouteData must contain an item named 'controller' with a non-empty string value.

What must I do in order to only have Overview/Index be possible for my route?

View 3 Replies

MVC :: Why Do Route Values Not Get The New Value

Jul 11, 2010

When I do an Html.RenderAction( action, controller, new { varName = value } ); if the original request had a parameter equal to varName, then the value is not changed in a render action.


1. Post to "C1/A1" with a string var _test = "abc"

2. Inside C1/A1 get some data and return a partial view

3. Inside the partial view I invoke an action on another controller. The action has an input variable with the same name and type (string _test) Html.RenderAction( "A2","C2", new {_test="fgh"});

4. the value in _test that arrives at C2/A2 is still "abc"

I've traced through it step by step, and the value used in the view render action call is correct, but in the next trace step, the value received at C2/A2 is incorrect.

If this is not an error, and creating a new route value to pass in render action is not the correct way to handle this, what is?

View 7 Replies

How To Access The Route

Mar 11, 2011

I'm using ASP.Net 4 URL routing on a web forms site.

I have multiple routes to a single page

routes.MapPageRoute("","our-services", "~/Information.aspx");
routes.MapPageRoute("","our-company", "~/Information.aspx");

On the destination page (Information.aspx) how can I tell which route was used to get there, for example was it from our-services or our-company?

View 2 Replies

Where To Use Route-name Of Routing In Mvc

May 19, 2010

i'm new to routing in aspnet mvc.. i have following code:


when i enter "localhost/school" in addressbar, it is giving 404 error instead it should route to my "schoolIndex" action

i have given route-name as "School" where it is used ?

View 1 Replies

How To Route Url With # Character

May 3, 2010

How to route url contains # sharp character like this:


to be:


View 2 Replies

Copyrights 2005-15, All rights reserved