MVC :: Subdomain Route Link Helper
Feb 8, 2011
I've created a new Route class, named SubdomainToAreaRoute, inherited from System.Web.Routing.Route, to handle subdomain.
The next implementation needed is to create a helper method to generate subdomain link.
For example:
Html.ActionLink("subdomain1", "account", "index") would generate:
http://subdomain1.example.com/account/index A series of other overloaded methods will also be implemented.
I undestand the geist of creating extension methods, which is one of the requirement to implementing these helper methods. Thus the main concern here is knowing what objects/classes to access and manipulate, and recommended algorithm to use.
There are some things that is unclear to me. For example, we register routes in the RouteTable.Routes (or simply route table), and whenever a url is requested, the url request is checked in the route table. If no url pattern matches, or if there is a matching pattern and the resource (e.g. web page) is missing, we receive a http error.
What is unclear here is in cases where specific physical path to a resource, like an image or javascript file is used for request. If these physical path url do not match the url patterns in the route table, how does an MVC application know to check for web application directory for the resource as the next step? As oppose to throwing an http error saying the resource can not be found.
This question may or may not affect my main concern here. But it is good to know if someone can explain it.
Focusing on registered routes, consider the following url route registration:
routes.Add("Home", new SubdomainToArea("", new { area = "Root", controller = "Home", action = "Index" } ) );
// route pattern 1
// intended to map to url: http://{area}.localhost.com
routes.Add("Default", new SubdomainToArea("{controller}/{action}", new { area = "Root", controller = "Home", action = "Index" } ) );
// route pattern 2
// intended to map to url: http://{area}.localhost.com/{controller}/{action}
routes.Add("Images", new SubdomainToArea("images/{*pathInfo}", new { area = "Root", controller = "Home", action = "Index" } ) );
// route pattern 3
// intended to map to url: http://{area}.localhost.com/images/{random path string}
How do I create helper methods to generate the appropriate url that matches these patterns?
I understand that extension methods for the UrlHelper class should be implemented to generate these url, and these url will be use in HtmlHelper class to generate the appropriate link tags.
In these helper methods, e.g. in the UrlHelper class, if passed a set of route values (such as controllers, action, areas and other url path details), how do we choose the appropriate route pattern that is registered in the route table, and then apply the route values to the pattern to generate the url?
How should I handle in cases where I don't specify one? What does the standard Html- Url- helper methods handle in case where no route name is not specified?
I understand the placeholder {controller}, {action} and {area} have special meaning and can be more easily identified and mapped to url pattern and so forth. How do we deal with custom placeholders we dynamically create, and use them for generating url?
View 6 Replies
Similar Messages:
Feb 27, 2011
I have made an asp.net mvc 3 application with an area called blog. I want to route this area to my subdomain blog.mywebsite.com. How can I achieve this?
How do I need to define my route? Do I have to configure the DNS?
Currently I just use the default area route. I can access my blog area for now at this way.
mywebsite.com/blog
View 1 Replies
Dec 20, 2010
On my page load I want to find out the subdomain of the currently visited site, I got my [URL] into a string, now how can I use RegEx to just retreive "sub" out of the whole string? note that www may and may not be there every time.
View 7 Replies
Dec 5, 2010
I have created an image helper I call it , I see it but it is not clickable ,In the source view I c it as a href , but it is un clickable.
[Code]....
This is the helper in the view :
[Code]....
View 2 Replies
Nov 15, 2010
What I want to do is take traffic that is going to shop.mywebsite.com and redirect or rewrite (I'm not sure of the terminology) the domain to be www.mywebsite.com/shop. Both shop.* and www.* are separate web applications (nopCommerce and Umbraco respectively) that don't seem to cooperate when I've tried to nest them. Both applications are in a Server 2008 R2/IIS 7.5 environment.
I've searched around stackoverflow and what I've found is a lot of answers to mapping the other direction (ie subfolder to a subdomain) but that's not what I'm looking for as far as I understand the problem.
The end goal is to combine the SEO reputation of the shop subdomain into the www subdomain. I readily admit that I might have this all backwards and am willing to try any suggestions I'm offered.
View 1 Replies
Jan 31, 2010
I have an app with multiple subdomains, subone.parent.com, subtwo.parent.com.
I have a logon page at parent.com/login. When a user logs in I redirect them to the proper domain based on which one they are a member of. This works fine.
FormsAuthenticationTicket ticket = new FormsAuth...
string encTicket = FormsAuthentication.Encrypt(ticket);
var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
cookie.Domain = subone.parent.com
Repsonse.Cookies.Add(cookie)
This properly authenticates the user for subone.parent.com and not subtwo.parent.com. However I would like to do the following.
If the user goes back to parent.com, I would like to know that they are logged in and redirect them back to subone.parent.com.
Is there a best practice for accomplishing this? Or do I have to set another cookie for parent.com?
I'm working in asp.net mvc if it matters.
View 3 Replies
Mar 13, 2011
I tried to mix asp.net 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}/", _
"~/article/articleview.aspx")
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
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
[Code]....
View 2 Replies
Sep 24, 2010
I have a url that I want to map routing to:
[URL]
where tabvalue is one of: "personal", "professional", "values" or nothing.
I want to map it to a route like:
Member/Edit/{tab}
But my problem is - I don't know how to specify such constraints. I'm trying this regex:
^[personal|professional|values]{0,1}$
but it only works when I use url
[URL]
[URL]
and doesn't work for
[URL]
how to specify the correct constraint?
P.S. I'm not using MVC, just asp.net WebForms
View 6 Replies
Mar 14, 2011
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?
View 2 Replies
Mar 15, 2011
i'm new to asp.net mvc2. i'm developed one project using asp.net mvc2 and vs2010 using linq to sql server. my project like a blog posting comment,
create tickets. my problem is when user register in my blog example my blog name is "helpdesk.com". when user register in my blog with the company name example "something". after registering the user i want to create one sub domain for this user like "something.helpdesk.com"
using this url "something.helpdesk.com" how to server my view pages. i'm not getting any idea. in this concept i have no idea about routing concepts. any body know please suggest me how to create sub domain and how can i server the view pages with in subdomain.
View 1 Replies
Nov 26, 2010
I'm using a BlogEngine.net for my blog and I would like to create 5 different subdomains and point to different subfolders(not redirecting). For example:
firstsubdomain.domain.com - domain.com/posts/helloworld.aspx
firstsubdomain2.domain.com - domain.com/posts/helloworld2.aspx
firstsubdomain3.domain.com - domain.com/posts/helloworld3.aspx
I'm using asp.net 3.5, C#, Windows Server 2008, IIS 7
View 1 Replies
Jun 15, 2010
Is it possible to create a subdomain using asp.net? Or is it possible to use url rewrite on IIS to create/cloak a subdomain.
Rewrite this page to http://www.mydomain.com/myprofilename into http://www.myprofilename.mydomain.com
View 6 Replies
May 7, 2010
I am using MVC 2.0 to create my application,my problem i s related to the routing. Actually in my application each user have required seperate subdomain,like
www.example.com/user1/ ,www.example.com/user2/ ...etc.the default domain is www.example.com.So how can i make it possible with routing in mvc.
i have tried like this,
routes.Add(new Route("{id}", new RouteValueDictionary(new { controller = "User", action = "login", id = " " }), new MvcRouteHandler()));
var defaults = new RouteValueDictionary(
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
routes.Add(new Route("{controller}/{action}/{id}", defaults, new MvcRouteHandler()));
But the problem is that it take deafult (www.example.com) directly to user login page.I want the default page as Home/index and when www.example.com/user1/ it will go to user login page.
View 1 Replies
Jun 15, 2010
I want to have a subdoman (sub.site.net).irst of all, I don't know how to copy my files to this registered subdomain. Second: I want to Redirect my whole website to a new sudomain. for example if a user types: "www.site.net" it automatically goes to "sub.site.net". is it possible? if yes, What should I change? Maybe in my master page?
View 4 Replies
Nov 7, 2010
I want to wipe a subdomain off the face of the internet.
So any page in the sitemap I want it to 301 redirect over to the homepage of the main www site...
Can that be done? I tried setting the re-direct in IIS, but it only worked if I hit the homepage (the subpages all 404d)
View 1 Replies
Dec 31, 2010
How to create sub Domain in asp.net. am created some pages in sample folder i need to create sub domain like sample.mydomain.com
how to integrate codings.
View 8 Replies
Jul 2, 2010
I got a website [URL] and I want to redirect http://www.example.com/folder to http://folder.example.com so if
folder has a page called example1.aspx [URL]
It should be called in this way:
http://folder.example.com/example1.aspx Is that possible that using IIS 7 and asp.net 4.
View 2 Replies
May 12, 2010
I am creating a social networking site and one of the requirements is to have the subdomain like URL for each user. For example, for the user1 his profile page will be user1.mysitename.com and for the user2 profile page will be user2.mysitename.com.
Can it be done using url aliasing? basically user1.mysitename.com should be www.mysitename.com/profile.aspx?username=user1
I will be hosting this in windows 2003 (IIS6),
View 1 Replies
Feb 9, 2011
I have an asp.net website. I want to add subdomain for a secondary language:
[URL]= main
[URL]= chinese
I have no idea where to start.
View 1 Replies
Jan 20, 2011
I added the following entries in the HOSTS file.
127.0.0.1 abc.localhost.com
127.0.0.1 xyz.localhost.com
Using the VS2010 ASP.NET Development server I am unable to run or execute the website.
When browsing http://localhost:2687/TestProject/ it shows up the default.aspx page. But when accessing http://abc.localhost:2687/TestProject/ it shows a website cannot be found page.
Is there anything else to be done when setting up subdomain on localhost.
EDIT: To make this work I removed the .com and in IE-->Connections-->LAN uncheck everything. Subdomains with port works are correctly getting forwarded. Nothing else need to be configured.
View 2 Replies
Oct 28, 2010
While writing an asp.net project i may have this url for testing/debugging
http://localhost:1234/
I have code that takes in account of subdomains. Can i make visual studios call the same code with
http://anysub.localhost:1234/
View 1 Replies
May 3, 2010
I have a portal say 'portal.mysite.com'. I have another portal say 'login.mysite.com'. Could someone tell me how I could use the same login credentials to login into the subdomain?
View 1 Replies
Feb 2, 2011
i have website [URL] this website got capability of host multiple shop sites with in... Now issue i am facing is that when we create sub site like this [URL] its working on production server. where as the code version i am running on windows 7.
I have stuck in a situation the error is occuring on subdomain site...
to reproduce that on my local machine... don't no what to do..
View 2 Replies
Aug 17, 2010
Just curious if subdomains can be generated dynamically. For example say I have [URL]. In a SQL DB is a list of cities. Can these be used to generate new subdomain for each city? (ie [URL], [URL], etc.) Or do I have to create every sub domain I want manually?
View 4 Replies