How to enable ASP.NET Web API Help Page documenting in Areas - asp.net

I'm using Areas to help organize my Web API. I essentially have 2 sets of APIs, one for performing account/user management and the other is using the service that I provide.
So my routing looks like this
"api/{area}/{controller}/{action}/{accountNumber}"
Before I started using Areas, the Help Page was working fine, but after I started using Areas it stopped generating the help documentation. Is there something I need to configure to get Areas to be included by the Help page?

I've used multiple routes to solve the same thing without areas:
config.Routes.MapHttpRoute("Foo",
"api/Foo/{fooId}",
new {controller = "Foo", fooId = RouteParameter.Optional});
config.Routes.MapHttpRoute("Foo_Bar",
"api/Foo/{FooId}/Bars/{barId}",
new {controller = "Bar", barId = RouteParameter.Optional});
Works fine with the HelpPage.
I've also tried AttributeRouting, but I prefer my routes.

Related

Permanent redirection not working

Having spent a lot of time wondering why it's so hard to do permanent redirection in MVC, I came across this page http://www.eworldui.net/blog/post/2008/04/ASPNET-MVC---Legacy-Url-Routing.aspx which made it look moderately straightforward.
I downloaded the sample code, copied all the helper classes into a new MVC project, and added the following to the RouteConfig.RegisterRoutes() method...
routes.Add("Jim1", new LegacyRoute("Default.aspx", "Home", new LegacyRouteHandler()));
The idea was to have requests for /Default.aspx mapped to /Home instead. However, this just gives a 404 in the browser. When debugging, it breaks on the LegacyHandler.ProcessRequest() method on the line that throws an "Invalid Url" exception.
Has anyone used this code that can advise? Or, does anyone have a SIMPLE solution for this? I have an old ASP.NET WebForms site that I've converted to MVC, and want to set up redirection. I can't believe how difficult it is.
Anyone any ideas?
In case it helps anyone, I did some more searching, and found a fairly simple solution that did work.
If you look at this blog post, you'll find a fairly simple approach that requires you to add some classes to your solution. I created a new class library, and added them there. I then referenced this from my MVC project, and added lines like the following to my RegisterRoutes() method...
routes.MapLegacyRoute(null, "Default.aspx", new {controller = "Home", action = "Index"});
routes.MapLegacyRoute(null, "About.aspx", new {controller = "Home", action = "About"});
routes.MapLegacyRoute(null, "Contact.aspx", new {controller = "Home", action = "Contact"});
Worked like a treat!
Hope this helps someone. It would have saved me hours if I had found this earlier!

How to setup durandaljs with Areas?

For the life of me I can't make durandaljs work with Areas. I'm developing an application with multiple mini SPAs, but I'm not sure how to set up durandaljs to work with it. I wasn't able to find anything online that can drive me in the right direction. The only similar question I found was this one, which is very vague.
My goal is to separate each SPA within it's own folder like so:
App
--areas
----area1
------viewmodels
------views
----area2
------viewmodels
------views
The router doesn't seem to have the concept of areas and no matter how I map the routes I get 404s when I call router.activate('page1'); after mapping with router.mapRoute('page1'); durandal is trying to get /App/viewmodels/page1.js.
Changing it to:
router.mapRoute('areas/area1/viewmodels/page1');
router.activate('areas/area1/viewmodels/page1');
results in another 404 fetching App/viewmodels/areas/area1/viewmodels/page1.js
I've also tried many other combinations which I no longer remember and can't seem to get it to work.
Can someone please post a working example of how to setup durandaljs with the router plugin and multiple mini SPAs (areas)? A link to an article document would also suffice.
You can use viewLocator.useConvention - maybe something like this:
viewLocator.useConvention(
"areas/area1/viewmodels",
"areas/area1/views",
"areas/area1/templates"
);
One good thing to realize is that useConvention() works in conjunction with any existing require.config paths setting. In other words, if you set the require.config so that "viewModels" and "views" are mapped to the right folders, then all is well.
For example, the code snippet above is functionally equivalent to:
window.require.config({
paths: {
"viewModels": "areas/area1/viewmodels",
"views": "areas/area1/views",
"templates": "areas/area1/templates"
}
viewLocator.useConvention("viewmodels", "views", "templates");
I a similar structure implemented in my application. I think that you have to put this piece of code, to do the viewLocator works properly.
viewLocator.useConvention(); //You can do that in you main.js
You can see more information here: http://durandaljs.com/documentation/View-Locator/
Also I recommed you to look the code of viewLocator.js, especially, the code of useConventionMethod.
Other possibility is to override the method convertModuleIdToViewId, to make it works as you want. But I think that using useConvention methos is enought.

How to build .NET web scraper for news articles about people

I am looking to create a simple webservice to crawl webpages on specific websites and look for a person's name. Anybody know if there are any examples out there of this, or can anyone help me with the start of this?
Edit: I should mention I want to do this with Visual Studio C#. I will only be looking at English news sites that I specify.
Here is a simple function that returns true if a Web page contains a person's name:
string response;
using (System.Net.WebClient wc = new System.Net.WebClient())
{
response = wc.DownloadString(url);
}
return reponse.Contains("John Doe");
For finding the links within the page, check out this question:Parse HTML links using C#
You can collect distinct Urls throughout the site and run the code above for each Url you find.
Also, type this into Google to see what they find. site:www.somesite.com "John Doe"
Using c# your best option for a crawler and parser (the two parts to your solution) would be to use functionality exposed by the HtmlAgility Pack, which can be found on CodePlex.
Refer to this answer for an example usage scenario: How to use HTML Agility pack

How to modify the SignalR Hub URL

I would like to use a different base hub URL than ~/signalr/hubs. How to modify this url, for example to ~/api/hubs?
Second question, may I use a different url for a different sets of hubs? For example:
~/api/chat/hubs
~/api/email/hubs
Thanks.
Ran across this, possible now with 0.5+:
RouteTable.Routes.MapHubs("~/api");
No you may not, it's hardcoded in the source.
No the proxy generated is for all hubs.
Well this question is old (4 years? wtf.. I always thought web sockets was kinda new).
... Well they(Microsoft) have new descriptive well written documentation on their website now
This could be a link only answer but if you are in a hurry.... On the server side at the startup or owin app config have somthing like this...
app.MapSignalR("/newCoolUrl", new HubConfiguration());
Ehhh sure you need to replace everything "/signalr" on whichever clients you are using to "/newCoolUrl" example
var connection = $.hubConnection("/newCoolUrl", { useDefaultPath: false });

SqlProfileProvider - can you use Profile.GetProfile() in a project?

I am attempting to use the SqlProfileProvider in an application and can't seem to use it the way I want to. I would like to be able to simply call up a profile like this:
Profile p = Profile.GetProfile("naspinski");
p.Organization = "new_org";
but I can't seem to find the correct way to use the GetProfile() that I seem to see scattered around the net. Is there a way to grab, read and modify profiles?
I am using it in MVC 3 and will not be actually logging in as the specific user, this will be pulling users from the db that are specified. Thank you.
To retrieve the profile:
var profile = ProfileBase.Create(HttpContext.Profile.UserName, true);
And here's the MSDN documentation. And a nice blog post about custom profiles.

Resources