MVC4 construct url with controller/parameter/action - asp.net-mvc-4

have a look to the following URL:
https://manage.windowsazure.com/#MYCOMPANY.onmicrosoft.com#Workspaces/CloudServicesExtension/CloudService/MYSERVICENAME/dashboard
It looks like the url is in the form {controler}/ActionName/{parameter}/ActionName
How can I generate such URL in MVC4/Razor?
Indeed, I want to build url in the form:
http://www.myservice.com/Configuration/{Source or Target}/{DomainName}/{ConfigurationType}
ex:
http://www.myservice.com/Configuration/Source/mydomain.com/ConnexionConfiguration
http://www.myservice.com/Configuration/Source/mydomain.com/AttributesConfiguration
Thanks.

You can either create per action routes, for each action, or include the controller name and action name in the url and then use something like this:
routes.MapRoute("Default","{controller}/{source}/{domain}/{action}")
so a controller called Configuration with an action called Setup and a domain of example.com and source of welcome would be
/Configuration/welcome/example.com/setup

Related

How to make seo url for Yii $_GET method using url manager?

I'm working on a site on local server. I have made a form to search country,state and city. After getting the results I see the URL formatted as URL
I want to make this URL as URL
So here I want to know about URL manager rules so I can make it as I want.
Simply add this rule in your url-manager
"site/searchme/<country>/<state>/<city>" => "site/searchme"
Now, you need to have an action with this signature:
public function actionSearchme($country, $state, $city)
You can access $country, $state, $city from url inside this action. For example if your url be like http://localhost/yii_1/site/searchme/UnitedStates/Washington/NewYork, $country will equal "UnitedStates" and so on.

Yii transform url from param/param/param/ to param/param?param

Suppose I have a url like:
site.com/param1/value1/param2/value2/param3/value3/param4/value4
I need to convert this url when a user writes it in url line to:
site.com/param1/value1/param2/value2?param3=value3&param4=value4
P.S. - the number of parameters is variable.
How can I do it?
You need to change the UrlManager Rules according to the situation.
You need to configure the Url manager to handle the first two params as path url and let the rest

How to add additional variables in yii url

I'm working with Yii framework and i'm trying to implement "create pdf" button on all sorts of different url's.
My first plan was to simply add variable to url where "create pdf" button links:
'url' => Yii::app()->request->getUrl().'&pdf=true',
And it works fine on all links except when i enter directly to site like: www.example.com. In that case there is no index.php in url so button link is unusable as it looks like this:
www.example.com/&pdf=true
Is there Yii way to append variables to url or I need to do manual checks?
create your links like this :
Yii::app()->createUrl('controllerName/actionName', array('number' => 2, 'name'=>'john'));
//or this if you want it with http:://
Yii::app()->createAbsoluteUrl('controllerName/actionName', array('number' => 2, 'name'=>'john'));
you can add your parameter(s) to the original parameters with the CMap::mergeArray($_GET, array('pdf' => 'true'))
and use the Yii::app()->createUrl or your Controller's createUrl function:
http://www.yiiframework.com/doc/api/1.1/CApplication#createUrl-detail
http://www.yiiframework.com/doc/api/1.1/CController#createUrl-detail

Multiple GET parameters in UrlManager

I am using Yii 1.1.14.
I want to convert
http://website.com/controller/action?param1=value1&param2=value2
to
http://website.com/value1/value2
How to do this in urlManager?
First, check this to hide index.php:
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x
Then, the route in config.php should be like this:
'<param1:\w+>/<param2:\w+>'=>'mycontroller/myaction',
The method myaction should accept $param1 and $param2 in its constructor to be passed automatically by Yii.
This would make your app unable to look for other controllers, because that rule will accept every route with 2 words separated by /

How to create a URL like "http://paramter1.xyz.com/"

How to create a URL where,the base URL contains a parameter. For example "blog.msdn.com". This "blog" is a parameter to the base URL "msdn.com". I want a URL like "blog.msdn.com", where "blog" is a parameter variable. How to create this type of URL pattern in MVC4.
in mvc you can change your url of your site page like your domain /controller/view
you can change character of after character of your domain like your domain/instead of controller name/instead of view name