Url with email address in ASP.NET MVC4 -


i have situation i'm using urls possibly contain email addresses. example:

http://myurl.com/edit/mike

or

http://myurl.com/edit/bob@whatever.com

according this stackoverflow question appears easy way around use querystring instead. there way set in routing rule, determine if value invalid , have fall querystring?

how this:

route:

routes.maproute(     name: "useredit",     url: "edit/{user}",     defaults: new { controller = "user", action = "edit" },     constraints: new { user = @"[a-z0-9]+" /*add valid characters here*/ } );  routes.maproute(     name: "usereditwithillegalchars",     url: "edit/",     defaults: new { controller = "user", action = "edit" } ); 

the route match urls /edit/mike , edit/?user=bob@whatever.com.

generating url works. example

@html.actionlink("1", "edit", "user", new { user = "mike" }, new { }) @html.actionlink("2", "edit", "user", new { user = "bob@whatever.com" }, new { }) 

produces same urls above

controller:

public actionresult edit(string user) 

note: 1) need check if user null 2) add valid characters constraint because don't know of them.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -