I'm developing a site with ASP.Net 4 which uses routing extensively. it displays pages for each client depending on the route data.
http://localhost/abc/manage/posts/ redirect to posts page of abc client
http://localhost/adidas/manage/posts/ redirects to adidas page.
now i need to do this using the subdomain way like adidas.localhost.com. i searched through SOF and found few solutions using MVC.
URL Routing across multiple subdomains
I have added the required wildcard dns, host file changes etc. and i understand that i need to read the hostheader to to determine the client. my question is where do i have to do this check, as im using routing without MVC i don't use MVC controllers. i need to do with ASP.net 4 routing. can someone give me an idea on this ?
Related
I'm trying to set dynamic routing in an asp.net core 3.1 MVC application. I need something like www.mysite.com/USERID/shop. Want to be able to read USERID and all routing for all other pages append and work as usual. I need the userid for sharing URLs, but the rest of the site is already configured for /shop /cart /register, etc.
I have an MVC5 web application which maps to a domain www.example.com. I'm using basic {area}/{controller}/{action} based routing in my webapp and would need to map a subdomain to a specific route.
For example:
subdomain.example.com needs to always server content from http://example.com/area/controller/action
Ofcourse the route has to work with ASP.NET MVC5 routing and also all query parameters and "hashbang" data need to be retained so that:
http://subdomain.example.com#/somethinghere?var=value redirects content from http://example.com/area/controller/action#/somethinghere?var=value
So the question is: is this achievable with IIS routing/rewriting and if so, how? Another option would be to write custom MVC5 route which binds to a domain and I would love to see someone point me to a right direction with that, too.
This will not be possible, anything after the hash is client side only and the browser will not send it back to the server. As it is not send to the server there is no way to rewrite it.
As an alternative you can consider changing your routing to use pushstate instead of hashstate
I wonder what options I have in MVC Routing that can redirect/translate the incoming requests to the sub-domain urls and redirect them to the new RESTful scheme.
OLD
http://conv.mc.siteexample.com/v01/?token=AB03959BM23DFC3
http://click.mc.siteexample.com/?cd=1&sd=828&dd=1
NEW
http://siteexample.com/api/uri/conv/?token=AB03959BM23DFC3
http://siteexample.com/api/uri/click/?cd=1&sd=828&dd=1
Also a side note that I am actually using MVC WebAPI Routing, but I am sure that this is not important.
You could take a look at the Url Rewrite Module in IIS. Then inside your Web API application you would simply use the standard routing.
I have a CRUD application written in Classic ASP (not .net) which transfers (routes) page requests to relevant servers using a loadbalancer DLL.
It works like this:
Someone requests for www.mywebsite.com/products
There is an index.asp under folder products that redirects the request to either:
http://www1.mywebsite.com/products
or
http://www2.mywebsite.com/products
based on a loadbalancer logic.
Another scenario:
Someone requests for www.mywebsite.com/products/details
There is a index.asp under the sub folder details within the products folder that redirects the request to either:
http://www1.mywebsite.com/products/details
or
http://www2.mywebsite.com/products/details
based on loadbalancer logic
The main issue with application is whenever I include a new page, I need to create a folder and index.asp page to redirect the page.
We have a CMS database which contains the details of all pages. So I want to create an MVC application to replace the existing Classic ASP application.
But I didn't find any database driven MVC applications and I'm bit confused by routing. Do I need to create a separate route for each main folder I have or should I create a generic route for all pages.
Any help would be appreciated.
You don't have to migrate to ASP.NET MVC just for the URL rewriting.
IIS 7 does have an integrated URL rewrite module and ASP.NET 4 includes routing as well.
IIS URL Rewriting and ASP.NET Routing
URL Rewriting in ASP.NET
Anyhow, if you search e.g. on Codeplex for ASP.NET MVC projects, you'll find a lot of them which are database driven.
You don't need to create individual routes for each seperate item. Think about the concept of querystrings (?id=15&day=monday). URL rewriting is pretty much the same.
Update
I've overseen that your talking about classic ASP.
The build in URL rewrite module in IIS 7 works also fine with classic ASP. If you are having an older IIS version you need a 3rd party ISAPI rewrite module.
Anyhow, switch it to ASP.NET MVC ;)
MVC would lend itself very well to sorting your routing problem. So would ASP.NET 4.
However, the problem you have is that you don't know enough to ask a precise question. Hence your confusion with routing in MVC.
I would therefore suggest reading the nerddinners tutorial. You can get a PDF download for free. To go a step further, read Stephen Sandersons book on MVC 2 (or MVC3 in a couple of months).
If you follow the nerddinners tutorial and Stephen Sanderson's tutorial, that will give you a better idea of how it works.
In short, this is how MVC works:
In MVC, you forget about files and folders.
Instead, you have Controllers and actions. The routes map the requests to the right controller and action.
The code in the actions then decide which View to stuff full of data (from a database or wherever, it doesn't matter). The Views are just templates that are told what to do and what data to display.
The Controllers ask the Model for the data that they want.
Ie, the data access is all done in the Model, neatly separated from the User Interface.
M: Model
V: Views
C: Controller
The above is probably meaningless to you. It is a VERY different mindset to ASP classic.
If you are coming from old ASP, you will have a long hike, but it can be done. I came from Access. Anyway, read the books, follow the tutorial and see if it is for you.
When you are ready, we will still be here to help with more precise questions.
Asp.net MVC routing in your migrated application
Based on requests you've shown here you can sort everything up with just default route:
{controller}/{action}/{id}
In your case you'd have a ProductsController with all the actions you need.
Load balancing application
But having an Asp.net MVC application is just one part. This application will run on both load balanced servers. All redirecting should be done before they hit the MVC application.
If you intend to continue using the same loadbalancer DLL you could create a different Asp.net MVC application with only one route definition:
{*path}
and a single controller and action that does it all:
public Load: Controller
{
public ActionResult Balance(path)
{
// decide for web server and attach path to subdomain
}
}
This should do the trick just fine as long as the overhead of this action is very small. Otherwise your load balancing logic will become the bottleneck of your application since all requests go through this load balancer (it does that now as well so bare in mind this is no different now; never mind the authentication process on different subdomains you may be using).
Load balancing alternative
You should consider using the web farm balancing capabilities on the IIS 7 that will run your application on several web servers (because that's what your load balancing does in the first place). Search the web for web farm information. You can start with this:
http://www.iis.net/download/webfarmframework
I have a classic asp project and a teammate created a new functionality, but it's in asp.net mvc. I also know how to work with mvc, but I never used classic asp and mvc together.
For example, is it possible, in this classic asp project, to have a link that will redirect to a mvc page on the same project?
Thanks!!
Yes, you can have a link point to any other page you'd like regardless of technology. Likewise for a redirect. To redirect in classic ASP, use Response.Redirect
Absolutely, the pages (and that term is used lightly in the MVC side of things) can link between each other without any problems. Now, any built-in authentication or session management or anything like that will be considerably more challenging, but if all the sites need to do is link to each other then they can do this like any other two websites. The ASP pages can host manually-crafted (vs. HtmlHelper-crafted) links to the MVC actions, and can host forms that post values to the MVC actions (provided the field names line up properly).
There's nothing inherently special about the MVC actions. They're just handling HTTP GET/POST requests like anything else.