ServiceStack ToPostUrl() extension method ignores virtual directories - servicestack-razor

I'm using ServiceStack.Razor C# in Visual Studio 2015 for a small internal project and am working (learning) from the sample projects. As part of my development, I host all of my websites and apis etc in virtual directories, so rather than
localhost/hello
i have
localhost/SomeProject/hello
The problem is however, that once the razor is being delivered from the virtual directory /SomeProject/ , the ToPostUrl() extension method creates an absolute path and so the logic fails:
<form action="#(new Hello().ToPostUrl())">
results in
<form action="/hello">
which breaks the redirect when the form is submitted. What is the correct way to handle this? A virtual directory doesn't seem like a particularly unusual use-case?
Thanks

ServiceStack's Reverse routing only resolves paths from ServiceStack's Route definitions.
You'll need to include the prefix to any custom paths/virtual directory where ServiceStack is mounted before the route.

Related

Local debugging of subdomain-based multi-tenant MVC app in Visual Studio 2013

I'm working on a multi-tenant MVC application that uses a subdomain per tenant, i.e.:
tenant1.domain.com
tenant2.domain.com
But I'm having trouble figuring out a productive workflow for local testing and debugging this. The best I could come up with so far is to define a site element for each possible subdomain in the applicationhost.config file, and setting the subdomain I want to test as the application root URL in the MVC project settings. This works, but it means I can't test more than one tenant in a debug session.
I've tried using wildcards in the bindingInformation, but it doesn't seem to work.
Is there any way to make this kind of testing less tedious?
The best method I found so far has been to include your subdomain as a querystring variable when debugging locally. Then, in your controller, determine whether or not you are debugging and if so, grab that querystring variable. Otherwise, you're live and you would parse your domain.
This is quite old, but still effective:
http://lonetechie.com/2012/09/25/multi-tenant-architecture-with-asp-net-mvc-4/
The difference being, you would add the option for local debugging and like I said above, grab the querystring variable. In his example, he goes to the trouble of modifying the hosts file on his machine. The querystring variable is the easiest way around that.

easy hack for routing codeigniter to third_party examples files

I have to install 10+ APIs in my third_party folder, each has it´s own examples files for testing oauth validation and other features.
without too many changes, has anyone found an easy way to hack the Codeigniter routing to execute files like
$route['hackToken'] = "/application/third_party/googleads-php-lib-master/examples/AdWords/Auth/GetRefreshToken.php";
Codeigniter expects to find a class derived from Controller at the target of a route. So, you will not be able to do this unless you create a Controller for each example.

use boilerplatejs with codeigniter

What is the best way to use codeIgniter with BoilerplateJS? should I put the codeIgniter folder in a BoilerplateJS folder or the contrary? Or something else? Need to make an authentifcation page in codeigniter and redirect the application in boilerplateJS.
Thanks.
I tried BoilerplateJS with CI in the following way:
Basically this is including BoilerplateJS in CodeIgniter folder.
I included all the BoilerplateJS code except the index file in to a folder named public which is in the root folder of CodeIgniter. The index file is placed in the views folder and will be loaded by a controller. (See the image)
For this to work some file paths had to be tweaked.
File paths in boilerplatejs index file (boilerplate.html in my case) had to be changed as follows:
./libs/jquery/jquery-min.js >>to>> public/libs/jquery/jquery-min.js
./libs/underscore/underscore-1.3.3.js >>to>> public/libs/underscore/underscore-1.3.3.js
and so on.
In main.js requirejs path configurations should be changed to:
require.config({
//Let's define short alias for commonly used AMD libraries and name-spaces.
paths : {
// requirejs plugins in use
text : 'libs/require/text',
i18n : 'libs/require/i18n',
path : 'libs/require/path',
// namespace that aggregate core classes that are in frequent use
Boiler : './app/core/_boiler_'
}
});
And in your controller you can load boilerplatejs by: $this->load->view('boilerplate.html');
I was thinking of integrating BoilerplateJS and CodeIgniter and probably use codeignighter-rest server for some time.
If all goes well I will share the code within the week.
A sample project is available at: https://github.com/slayerjay/codeigniter-boilerplatejs
EDIT Adding my view on CodeIgniter and BoilerplateJS
Firstly I have not (yet) done any major projects with BoilerplateJS and Codeigniter. But I have done projects using CI and the CI REST Server and know BoilerplateJS in and out.
I do not have much experience with other PHP frameworks (I have meddled with cakePHP and some others) but for me CI helps me to organize my code according to MVC pattern in a clean way, and provides excellent helper libraries and documentation.
As the OP rightly said, authentication is handled best outside BoilerplateJS and this can be done nicely with something like ion-auth for CI. After the user is authenticated and the SPA is loaded, the rest of the calls will be handled by the CodeIgniter REST server.
In this case you won’t be using much of the View aspect of your MVC architecture, but CI’s models and helpers would be of great help.
If you just need a simple REST server you can go with some lightweight solution that just provides REST type routing, but in many cases you will need to interact with a database and do some data processing.
So if you have decided to have a PHP backend for your application, Codeigniter with the REST server is a good choice.

Using a Webform in an MVC3 Area

I am trying to integrate an old ReportViewer Webform into my current MVC3 project. I would like it to be available at http://<server>/Reports/ViewReport.aspx. At first I created a folder in the root of my project titled Reports, dumped the page in there, and it worked just fine.
However, I now have an Area also called Reports, and I had to get rid of the folder in order for the default routing to work correctly.
How can I configure my routing so that the Webform URL appears to be coming from Reports even if it's physically elsewhere in my project?
The easiest way to do this is to use IIS URL Rewrite module. No changes to your application's code or routing. Just place your webpage somewhere in some non-MVC related folder that is also accessible.
http://www.iis.net/download/urlrewrite
But otherwise you could try putting your file directly in area folder as the RouteCollection.RouteExistingFiles is by default false which means that your file should be processed by the usual Asp.net web forms pipeline.
The most important thing is though that you don't put your file inside a folder with configured System.Web.HttpNotFoundHandler handler. By default Views folders have these configured so files within sub-folder tree are inaccessible from request level. Application of course can access them (that's how MVC works anyway).

MVC 3 Content and Relative Path is not working when deployed to IIS 7.5

I am developing a MVC 3 Web Application and just tried to deploy it on IIS 7.5
The page is shown, but all the images as well as url path is not working at all.
I search through a lot of sources and found out that it seems to be compulsory for a MVC application to have all path being enclosed in either:
#Url.Action
#Url.Content
#Html.Action
and so on. So I tend to change all my relative path by using those valid method.
I understand it should be a correct way to use all those valid mvc helpers, but I am just a beginner and this is my first web application. My question is:
Is it possible to use any method to "resolve" the relative path so that it can be found even after deployed?
Really need help here... thank you very much....
You are not correct that you need to use those helpers for all URLs. There is nothing to prevent you from outputting URLs 'manually', as literals, or as you have done above.
Something wonky has happened with the paths of the files on your server upon deployment, most likely.

Resources