Hi Guys,
So the project we started as of today I am taking care of web side of things. So may be with occasional posts on PHP I will be writing few posts on Javascript, Webservices and ServiceStack.
I am not going to explain what ServiceStack is. You are here because you already know about it. In this post I am going to show you how to set Index page after you setup your ServiceStack successfully.
By default when you browse you are shown metadata page. This is because you haven’t set the default redirect path to your default page (Web service). I would use Page because that falls in line with web terminology.
So generally you dont want users to see your metadata page if you’re planning to open your software to browsers.
Here is what I did
The main configuration is made in the app host Configure
method. I believe you have access to that CS file. in your configure method add this line
1 |
DefaultRedirectPath = "Index", // Index here is your Webservice |
1 |
So my Configure method looked like this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public override void Configure(Funq.Container container) { //Signal advanced web browsers what HTTP Methods you accept. base.SetConfig(new EndpointHostConfig { GlobalResponseHeaders = { { "Access-Control-Allow-Origin", "*" }, { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" }, }, DefaultRedirectPath = "Index", // selecting default service AllowJsonpRequests = true, MarkdownBaseType = typeof(Markdown.CustomMarkdownPage), }); // Set up routes for REST API. base.Routes .Add("/index", "GET") ; } } |
Advertisement
Because I am using markdown templates I will define a Index.md file which for me has nothing but “Hello world” in there. Make sure that Property “Copy to Output Directory” has value “Copy Always”
Now lets check what my Index.cs file looks like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
namespace jcorg.WebServices.Api { public class Index { } public class IndexResponse : IHasResponseStatus { public ResponseStatus ResponseStatus { get; set; } } public class IndexService : RestServiceBase { public override object OnGet(Index request) { return new IndexResponse { }; } } } |
Nothing much just return whatever is in there in my Index.md file that will be parsed automatically. So now when I try to browse my webservice as HTML I see Hello World on my screen rather than metdata page that highlights what web services are available.
I have left some room for you to improve. My motive was to give you insight on what variable we need to set to change the default metadata page load to something else. In my next post I am going to explain how you can disable metadata altogether.
I hope that helps.
Cheers,
Advertisement
Awesome! Its truly awesome post, I have got muych clear idea regarding
from this post.