With reference to the documentation 'Controlling URL behavior', I have multiple sites and the logical structure has some of the nodes from one site under another.
So I have a sitemap in each site which represents this. When running in debug, it works fine and the breadcrumb links are ok - using the controller/action/preservedRouteParameters/hostName. BUT when deployed to the live site, an extra part is added to the link.
e.g. In DEBUG - From site 2 (localhost:1234) a link will resolve to 'site1(localhost:5678)/Controller/Action/PreservedRouteParameter
Where as In RELEASE - From site 2 (www.site2.com/events) a link will resolve to 'site1(www.site1.com)/**events/**Controller/Action/PreservedRouteParameter
so my question - is there a solution to my problem (having the extra events in there?
WORK AROUND
I couldn't figure this one out. I did however come up with a way around this....
Create a new controller (or use existing)
Use redirect:
public ActionResult myRedirectAction(int id)
{
return Redirect("http:localhost:1234/Controller/myAction/" + id);
}
Related
I have a problem to make a decision for putting Category/Path on URL Routing. Assume I have some products in my sample Web Application those attached to some categories. For example:
Book1 Attached to -> Category1 | Category2
Book2 Attached to -> Category1 | Category2 | Category3
Book3 Attached to -> Category2 | Category3
And defined routing map for products is:
url: "{controller}/{action}/{languageCode}/{category}/{product}"
defaults: new { controller = "Home", action = "ViewItem" }
So possible routing for Book1 are:
[Domain Name]/Home/ViewItem/en-US/Category1/Book1
[Domain Name]/Home/ViewItem/en-US/Category2/Book1
And possible routing for Book2 are:
[Domain Name]/Home/ViewItem/en-US/Category1/Book2
[Domain Name]/Home/ViewItem/en-US/Category2/Book2
[Domain Name]/Home/ViewItem/en-US/Category3/Book2
I want to save and know current category but have single unique URL for each product(For search engine tracking and sharing URLs purpose). I think about using Session Variable or ViewBag even Cookie, But each of them has own limitations and cons. For example using cookies may cause some troubles: if set expiration time too small, it may lost current path when user pausing on some pages and if set it too long, may lead user to old browsing path even user requested for home page in new opening browser because of existing cookie (Except that, I'v some experiences with cookies and I believe that is not working precisely all times), About Session and ViewBag I don't know if using them is the best idea, So can anyone share tested solution or good idea? I will appreciate that.
You should have the page mywebsite.com/product1 (the canonical version of the URL). Including all the versions of the URL won't help. Likely, it will just confuse Google and may lead to Google ignoring certain URLs
Even if you put in the canonical version and have the rel canonical tag on your pages, Google may still choose to treat another version of the URL as canonical.
Ideally, then, I'd solve the real problem here and just have one version of the product URL on your site (have the versions with the category in the URL redirect to the version of the URL with no category in the URL). That way you don't even have to worry about all the issues duplicate content may cause.
I suspect this isn’t a routing problem, rather an architectural issue. I think that the “language code” and “category” should be an attribute of the Book object, rather than being a part of the route.
You would then have URLs like:
{domain}/{controller}/book/id
And for “category” specific or “language code” specific views, you could have URLs like:
{domain}/{controller}/search?languageCode=enUS&category=1
This would still be perfectly RESTful and in my opinion, much simpler as well.
I've encountered strange behavior an can't find what is going on, hope somebody will give an idea.
So there is simple and standard route map:
routes.MapRoute("Category",
"category/{categoryName}/{id}",
new {
controller = MVC.PublicProduct.Name,
action = MVC.PublicProduct.ActionNames.Index,
id = 1
});
thing is, that instead of generating this:
http://staging/category/sunglasses/14
it gives:
http://staging/?action=index&controller=publicproduct&id=14&categoryname=sunglasses
strange things are:
1) if I enter right url into address bar, it works
2) it behaves so only in staging, on local machine (also IIS7) and production, it works as supposed, so I guess it is some kind of IIS setting.
UPDATE:
One of samples how url's are generated:
My Cart
Deleting site from IIS and disk and creating fresh one solved the problem, luckily this was staging, so no one was harmed.
I seek some guidedence here ... ( I'm not sure if this is the best title )
At the moment I prepend a "server name" to the url like this:
server10.example.com
This works fine, except that I need to handle all the subdomains on the IIS and I'm not sure google are happy about jumping around from sub to sub to sub, when it seems the links to the other servers.
I'm kind a hoping for a nice way to archive this wioth asp.net mvc.
Most pages are related to a "server" ... there are however a few info pages, contact, home that dont really need a valid "server" name ... but could just be "na" for not available, but the name need to be maintained, if there is already a selected server, when a user are keeps browsing the site. This needs to be as transparent as possible when I need to create the links to the diffenrent pages.
I could extend the Html Action() extensien to automatically add the selected "server" from the previusly request to the page.
In the format:
/{serverParameter}/{controller}/{action}/{parameterInfo}
And if no server is selected, just add "na" as the {server} placeholder.
I'm not sure if more information is needed, but please let me know if ...
I tired of extracting the selected server from the domain part and the other way also seems better, I just can't think of a good way to structure this ...
Updated
90% of all the pages are about a server that the user select at some point. Could be server10, server9, server20 ... just a name. I want to maintain that information across all pages, after the users has selected it or else I just want it to be f.ex: "empty".
I mostly looking for an easy way of doing this or an alternative ... atm I'm prepending the serverParamter to the url so it ends up being: "serverParameter.example.com".
I want to end up with something like
http://example.com/{server}/{controller}/{action}
instread of
http://{server}.example.com/{controller}/{action}
If I understand your question correctly, you just wish to group different collections of content together above the controller/action level. If that's the case, have you considered using ASP.NET MVC areas?
Just right-click on your project, and choose Add -> Area.... Give it a name (what you're calling "server"), and then you can add content, your own controllers, actions, etc. Under this area. You will automatically be able to access it via /AreaName/Controller/Action/etc.
I went with the already impemented routing in ASP.NET MVC.
{server}/{controller}/{action}
When creating the links it takes the set value for {server} and places the value when generating URL's, so I only need to supply controller and action in the #Html.Action helper method ... this could not have been more easy.
I'm not sure why I did not think about this. One just gotta love routing.
I'm designing an ASP.NET MVC Application in which I've constructed multiple Action methods for a single view with [ActionName("Name-Of-Action")] attribute with each methods.
**E.g ViewName= Contact.aspx
controller Action methods like :
[ActionName("Contact-us")]
Public ActionResult Contact_us()
{return view("Contact");}
.
.
[ActionName("contact-now")]
Public ActionResult Contact_Now()
{return view("Contact");}
.
.**
and so on...
I wish to make this site SEO Friendly, Can you please mention the pros and cons of calling a single webpage with different ActionMethods(URLs) in terms of SEO Scenario.
Thanks in Advance..
As with #naveen as specified, you could be penlised for duplicate content. If you really need to have different URLs for your content, you would need to use a canonical link tag so search engines know that the content is the same as the other page, and is not considered duplicate.
<link rel="canonical" href="http://www.mydomain.com/contact.aspx" />
This is quite prevalent in shopping cart systems, whereby you could have a product in multiple categories, but you make all of the content essentially canonical to a single URL, e.g.
1. http://www.mydomain.com/products/jellyfish.aspx
2. http://www.mydomain.com/products/sealife/jellyfish.aspx <-- canonically the same as #1
This will definitely affect you rankings adverslye if we sre talking not only about contact page. Your site will be penalized for duplicate content.
A good approach will be to fix one as ur desired url and Response.RedirectPermanent on the others. Stack Overflow deals with this issue like this.
Test for yourself by playing with our current url by deleting the slug or altering it. You will see 301(permanently redirected) issued in the console to the actual url.
Hope this helps.
I've got a very old php application (1999) that has been worked on during the last ten years. At this point the app starts to show it's age so i'm in te progress of migrating to a "new" framework, symfony 1.4. But since the app is very large, i cannot do this at once. So i'm planning to wrap the old app into the new symfony app, and convert functionality by functionality.
First step in this transition was making the old app appear in the new symfony app. So, i've created the "frontend" application, added a "legacy" module, made it the default homepage, and i've put everyhting i had in my index.php (all pages went through this index.php) in the indexSuccess.php file for the indexAction. I've added the code in the "view" because there are also functions in it and changing that setup would take me more time than i want to spend on the old app.
Unfortunately i've now got an issue with global variables. Let me give you an example (i would have never made this register function like this, but it is, so please look past that.
$session = new ps_session;
$demo = "this is a demo variable";
$session->register('demo');
In ps_session i have this method
public function register($var) {
global $$var;
$_SESSION [$var] = $$var;
}
So it should put the content of $demo in a session var named "demo". Clever right :) Anyway, var_dumping shows me the that $$var is "null" and $demo is filled if i var_dump before and after calling the function. Exact same code without symfony and it returns the correct content.
What am i missing? The global call is spread out in all area's of this massive app so i really don't want to switch to something else, so i'm hoping for a quick fix :)
Maybe relevant, the all code except the index.php content are in frontend/lib/legacy/ folder, the index is in frontend/modules/legacy/ (if there is some scope issue i'm missing)
I think that since your indexSuccess.php file is included inside a function (more precisely, here : lib/vendor/symfony/lib/view/sfPHPView.class.php:185 ), this can't work, because $demo is no longer in the global scope. I don't see any easy workaround for this...
I think you should create a legacy folder in /web , and use routing to redirect to it if the url corresponds to something not migrated yet.
I went with putting the entire old site under web/legacy and redirecting from the default index action to the legacy folder. Most of the url's were made by mod_rewrite so easily fixed. The other url's went through a function so fixing was ok, and only a few were hardcoded. To make it totally transparant, i only need to redo the homepage to start from, so i don't have a visible /legacy/ in my url. Thanks for the help!
I agree with greg0ire that this is an issue with the way sfPHPView includes indexSuccess.
Could you simply require index.php in the default/index action?