I've seen a few questions asked about this, but haven't seen any the same as it (or solved)... So here it goes...
I have two ASP.Net MVC applications, one nested inside the other...
example.com
---sites
------example1.com
Both sites technically work fine, however all URLs for the example1.com domain are resolved to example1.com/sites/example1.com/.
I have the application roots setup correctly in IIS and am using #Html.ActionLink("Home", "Index", "Home") and #Url.Content("~/images/image.png") type references for links...
UPDATE
It looks like the host is showing the HttpRuntime.AppDomainAppVirtualPath is returning the wrong path, /sites/example1.com/ instead of just /.
Any ideas, things to try? Anything would be greatly appreciated.
Turned out to be that the host used some sort of a custom ISAPI extension to route domains to sub directories, and didn't create true application directories. So that explained all of the issues...
Related
Ok I had a huge Issue giving this a proper title, my excuses for that.
Anyways I have started slowly to look at Web and ASP.NET again, I am a C# developer but I have mostly worked with Windows applications the past 5 years or so, It is not that I haven't touched the web as such in that time, but this is as web services (Restfull as well as the ugly SOAP services) I have also worked with more "raw" web requests.
But I have not worked with IIS or ASP.NET in all that time.
What I would like to do is hos a web page that uses a URL style I could best describe with "like rest", hence the "Restfull urls" title. Because I think most people thinks of such URL's in terms of:
http://example.com/item/
http://example.com/item/23/
and so forth. Not that they have to look like that, however I would like to use such URL's instead of
http://example.com/item?id=23
I know subtext does this, but i have not had any luck finding it in their code base.
Now as far as I can tell I could just implement some IHttpHandler's, but at least for the examples I have seen of that, they write the page source back in code, and I still have master pages etc. I wish to use instead of taking over all that stuff my self, I really just kinda wants to route http://example.com/item/23/ to http://example.com/item and asking for the item with id 23...
I hope this makes sense at all >.<... And that someone has some better examples at hand that what I have been able to find.
You can achieve this using Routing here is a link to an MSDN blog, The .Net Endpoint - Using Routes to Compose WCF WebHttp Services that should get you started.
If you're looking at asp.net/IIS, another option to look at is ASP.Net MVC. It's pretty straight forward to create RESTful services.
Here's a tutorial:
http://www.codeproject.com/Articles/233572/Build-truly-RESTful-API-and-website-using-same-ASP
So here are your options-
For .net 3.5 sp1 framework with IIS7 you can use asp.net routing feature to have MVC style urls that you mentioned should create a custom route handler implementing IRouteHandler interface as explained here How to: Use Routing with Web Forms and register your route rules in Application_Start method in Global.asax. For your example you can register a route like this
routes.Add("ItemRoute", new Route
(
"item/{itemId}",
new CustomRouteHandler("~/item.aspx")
));
and then you can access itemId in your routed item.aspx page by checking request context item
requestContext.HttpContext.Items["itemId"]
For .net framework 4 MVC you dont have to create a custom handler, you can directly use
routes.MapPageRoute("ItemRoute", "item/{itemId}", "~/item.aspx");
in you global.asax Application_Start method.
This link explains more about the Routing
A way of achieve this is using URL rewriting.
If you're planning to host your Web application in Internet Information Services 7.x, you can take advantage of IIS URL Rewriting Module:
http://www.iis.net/download/urlrewrite
URL rewriting is just mapping a friendly URL to an unfriendly, common one, which is programming-friendly to inspect GET parameters.
For example:
http://yourdomain.com/item/48 => http://yourdomain.com/Items.aspx?Id=48
I have an application written in .NET 3.5 with C# as the language. I'm using Web Forms, but using url routing with the routes defined in my global file. Everything is working as expected. In order for the pretty paths (see: user/665 instead of user.aspx?uid=665) to work properly, I had to add a wildcard mapping in IIS5.1 (local box, not test, staging, or production) the aspnet_isapi file for the 2.0 framework. Everything works fine.
Now, my site needs a plugin for PHP. However, the PHP files are now being serviced by ASP.NET due to the wild card mapping, and hence are not processed by the PHP interpretter. Is there any way to get around this? Would I have to add some sort of handler to my web app that will take all PHP requests being handled by the ASP.NET framework and have them routed to the PHP engine? Is there an easier way? Maybe a way to exclude them in the web.config (PHP files) and have them served by the proper PHP engine?
Thanks all!
-Steve
This is a solution, but is not an elegant way (IMHO):
Create a virtual directory
Have it point to the folder with the files (in this case, a PHP plugin)
Give it the proper permissions
Change the config options for the virtual directory in IIS and make sure the wildcard mapping for that directory is removed.
This works like a charm for my situation. However, is there any way to not have to deal with virtual directories?
The problem is that the PHP extension needs to be registered.
In IIS Manager right-click on Default Website -> Properties -> Home Directory -> Configuration
Under Application Mappings make sure that .php is added and is it pointing to PHP.EXE. There should be an entry like this: extension .php, executable path C:\PHP\PHP.EXE %s %s
From what I gather, the problem is that ASP.NET is attempting to route your PHP requests, so what I would do is add a StopRoutingHandler() to your routes in the global.asax. Something like this should work:
routes.Add(new Route("{resource}.php/{*pathInfo}", new StopRoutingHandler()));
Edit: Be mindful that routes are processed in order, so I would add this to the top of your routes.
I'm attempting to create an MVC application as a sub-application to my standard Asp.Net Web application. Both of these projects are inside the same solution. While the parent application appears to be going fine, I'm having trouble getting the sub-application to work. After some massaging of my two web.configs, I was able to get the Asp.Net runtime to accept the configurations, but I have been unable to browse to any of the pages/controllers in the MVC application, including the root of the sub-application ("http://RootSite/SubApplicationName/"). I continually get 404's.
Actually, I do get a response when going to the url "http://RootSite/SubApplicationName/Home/Index/". It redirects me to index.aspx in that folder, and throws this error:
The view 'Index' or its master could not be found. The following locations
were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
The sub-application in IIS (7) is set up fairly straight forward: it's set to run in the same application pool as the parent app, which runs Asp.Net 2.0 in integration mode.
My suspicion is that I have something in the web.configs that is throwing it off. Are there things regarding, say, HTTPModules or URL authorization modules, etc., that I should confirm aren't getting in the way of MVC?
Also, in the global.asax.cs file, should the default route be different? By default, the url parameter passed to routes.MapRoute is:
"{controller}/{action}/{id}"
Should it be preceded by the name of the sub-application, like so?
"SubApplicationName/{controller}/{action}/{id}"
I attempted a change like that, but it did not fix things.
Any ideas are much appreciated. Also, general information about setting up an MVC web application as a sub-application would be great.
Thanks.
I did something similar, however not the same, I had to load views from a separate dll. In my case it was a class library, not a different web app, but it should work the same as far as I know.
The first thing you have to do is to create a VirtualPath Provider to tell the routing engine how to look for your stuff in the subapplication views. A great explanation of how to do this can be found here:
http://www.wynia.org/wordpress/2008/12/05/aspnet-mvc-plugins/
I'm sure that will get you started ;)
Make sure that you haven't made any spelling mistakes in the names of your Views directories. I was receiving the same error message and after 30 mins of head scratching realized that I had misspelled the folder name for one of my Views. The IDE did not pick this up in any meaningful way (i.e. it would have been nice if it explicitly told me that the path to the view that I was referencing was not correct -- "not found" could mean a few different things).
Sub application doesn't suite to MVC web application directly. you have to write a lot of hacked code in global.asax. Use sub domain rather than sub application.
Sorry for the possibly misleading title of this post. Couln't really think of anything better at the moment.
Anyway, I have a site set up that allows users to search our customer database. I have a separate section of this site listed under a "reports" directory, which is used to generate billing reports, subscriber counts, etc. Apparently our users are confused about having to type in the reports folder on the url: http://maindomain/reports/.
I'm wondering if there is a way to create a new domain that points to that specific folder. In other words, users go to http://reportsdomain/ which would be an alias for http://maindomain/reports/. The solutions that I've considered are as follows:
Create a new site in IIS that points to the reports folder (which is a sub folder in the other site... seems like a bad practice since then two seperate IIS sites will be doing caching for that site, maintaining session/application state, etc).
Build a IIS module to do URL rewriting
Of those two options, I'd probably go with 2 before 1. Any other ways to do this that I'm not thinking of?
Thanks in advance for your help.
Respectfully,
Chris
Option 2 would be more ideal than the extra overhead of having two sites.
Using the Microsoft URL Rewrite Module for IIS 7.0
If you're okay with the user typing in the main URL and then being forwarded to the new URL, you just set up the http://maindomain site in IIS and then on the "Home Directory" page, set it to forward to http://maindomain/reports/.
While this isn't as clean as the URL re-writing option, it's painless to enable, and it seems like this might be the option you're looking for.
It would also be possible to handle this at the DNS level.
EDIT!! I should add that this site runs perfectly locally. It's only when deployed that there's this issue
ORIGINAL POST:
I have a site I just put up http://splattonet0.web704.discountasp.net/
Which loads the Index view of the Home controller just fine. However, when one clicks the links to the left, the webserver is looking for the relative paths (ie E:\web\splattonet0\htdocs\Home\AboutMe) which is incorrect, since Home folder is of course under a folder called "Views"
I've made MVC sites before and have never had this problem. I can't see any difference between this or any other site I've done.
My code in my master template for the link section is as follows:
<div id="navContainer">
<ul id="mainNav">
<li>Home</li>
<li>About Me</li>
<li>Skills</li>
<li>Resume</li>
<li>Experience</li>
<li>My Websites</li>
<li>References</li>
<li>Projects</li>
<li>Hobbies</li>
....etc
</ul>
</div>
I have the same problem with and without the preceeding foreslash in the href property. I've decided to keep it there since that is how my other sites (that work!) are styled.
Can anyone shed some light on this for me? Thanks!
FURTHER EDIT:
I have been asked to provide code from an MVC site on this server I have written and that works fine. The link code in the other site (YorkCentre) is the same style: <li>text</li>
The code:
<li>Archived News</li>
<li>Board Of Directors</li>
<li>In The Media
...
</ul>
/Home/Index should be calling the "Index" action of the "Home" controller, assuming you're using default routes. The fact that "Home" is under the "Views" folder is irrelevant for MVC.
If the code is the same in both locations, and the issue only happens in one, perhaps the answer lies not within the code. The following are some troubleshooting tips which may help, as I don't know exactly what the issue is without more information about the two environments.
What are the web server platforms for your local environment and the server environment? Are you using Visual Studio and Cassini locally, and IIS remotely? If so, which version of IIS? If not, what is the platform? In any event, is the target server configured correctly?
Check to make sure your routes are set up correctly on the target server. This is especially true if your target server runs IIS6 -- IIRC, IIS 6 needs some special configuration help to deal with the standard routing in ASP.NET MVC.
If all of the above don't help you trace this out, try to replicate it locally by creating a new MVC site and merely dropping your existing files into it. See if that succeeds or fails.
Do you have other successfully-executing ASP.NET MVC apps on that server? Check their configurations against your new site's.
I have resolved the problem! In DiscountASP I have changed the Application Pool Pipeline Mode from Classic to Integrated and that results in my views being properly rendered.