I have a "Tools" area of the MVC3 site I'm currently working on. One of the tools I'm integrating on the site I need to run in a virtual directory. Setting up a virtual directory under the /Tools folder works fine for the app itself, but for navigation to /Tools/, I'm getting "Directory listing not allowed". How do I tell IIS to let MVC routes handle this URL?
We'll be using IIS6 in production, so it's important for it to work with that.
Thanks in advance.
EDIT: For clarity, here's the setup:
/Tools/RoutedTool1
/Tools/ToolInVirtualDirectory
/Tools/RoutedTool2
/Tools/
The routes for the routed tools work fine, but since I had to create a directory under the root to setup the "ToolInVirtualDirectory", IIS is hijacking the "/Tools/" request and trying to send it to the directory, ignoring the route.
You should set routes.RouteExistingFiles = true in Global.asax.cs.
Remember that since this property plays at global level you have to ignore the css files and other stuff you don't need to handle by the routing infrstructure before setting this. For more idea please refer this post.
In your RegisterRoutes section in Global.asax, you add ignore routes that the routing system ignores. There should already be an example for .axd's in the config.
Related
Entry level web developer here, thank you in advance.
A very basic single page website starting from Empty ASP.NET Web Application adding each and folder file from scratch. Everything works fine locally bare bones. I'm trying to configure the start page in the subfolder "html" to the file index.html. I get the default "This website has been successfully created" after publishing. Azure web service is working fine because I can go to site.azurewebsites.net/html/index.html to see my page after it's published.
Right clicking the project and going to properties to set as start page, or going to Properties>Specific Page doesn't work as suggested here for deployment but works fine locally. Altering the web.config file as suggested here gives me an internal server error that is fixed once I remove the code
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="html/index.html"/>
</files>
</defaultDocument>
</system.webServer>
I tried different variations of this all with the same internal server error. Is my syntax correct?
I then created a global.asax file and changed the Application_Start line as suggested here:
protected void Application_Start(object sender, EventArgs e)
{
Response.Redirect("/HTML/index.html");
}
Same result.
Lastly, I created an App_Code folder with a RedirectHandler.cs file as suggested by Rion Williams's last suggestion (first link) along with his code and sure enough I get the same result.
"This web app has been successfully created" after publish but I see my desired start page after adding /html/index.html to the end of the url.
Understanding how basic this problem is I took extra care to exhaust as many google searches as I could find relating to the topic before asking this question. My first question on StackO so my reputation is too low to link each page I found. My next attempt is to just start a brand new MVC project and painstakingly rearrange every single file that way. I'm confident that will work but I didn't want to leave this simpler method without learning from what I did wrong especially when I know the answer is going to derp-slap me in the face.
Have you tried to configure the default document under the configuration tab for your website in Azure portal?
With a lot of changing file locations around, clearing cache, and rebooting to avoid server and runtime errors, #hernandgr had the simple option I hadn't known about (shame on me) and funny enough couldn't successfully google about.
It turns out that I didn't need to do any of the steps I had tried to configure the start page beyond just changing it in the configuration tab in the Azure Management Portal. I deleted the global.asax file and the App_Code folder completely, didn't need to touch the web.config in any way and didn't need to implement MVC.
One thing to be noted was that making index.html my start page through Azure seemed to push it up a directory so my CSS, JS, LESS, fonts, and images folders had to be moved up as well to display the page properly.
I have a directory which hosts my web services based on ServiceStack. Inside the directory I have a help folder which has some html pages in it. However when I try browse to those pages, ServiceStack thinks that I am trying to hit a route and gives me "Handler for Request not found".
Is there any way to tell ServiceStack to ignore certain routes? If a route matches a directory present in IIS surely it can't be a service route?
http://www.example.com/exampleservice/metadata <-- fine
http://www.example.com/exampleservice/help/main.html <-- has nothing to do with ServiceStack as it's a directory
This looks to have been nicely implemented in ServiceStack v4. Demis posted about it here.
The Virtual FileSystem is now fully integrated into the rest of ServiceStack, this enables a few interesting things:
The Config.WebHostPhysicalPath sets where you want physical files in ServiceStack to be serve from
You can now access static files when ServiceStack is mounted at a custom path, e.g. /api/default.html will serve the static file at ~/default.html
By Default, ServiceStack falls back (i.e when no physical file exists) to looking for Embedded Resource Files inside dlls.
You can specify the number and precedence of which Assemblies it looks at with Config.EmbeddedResourceSources which by default looks at:
The assembly that contains your AppHost
ServiceStack.dll
I have three different environments that I need to be able to use url routing with:
Debug
Live
Demo
The home pages for these three are:
http://localhost:48060/Login.aspx
http://192.168.0.145/Live/Login.aspx
http://www.website.com/Demo/Login.aspx
Both Live and Demo sit in the same Default Web Site as web applications (live is exposed only internally, while demo is exposed externally).
I want to map these to
http://localhost:48060/login
http://192.168.0.145/Live/login
http://www.website.com/Demo/login
Without triplicating every route mapping, what is the recommended approach?
Thanks!
Example of how I add the route for Debug env:
routes.MapPageRoute("Login", "login", "~/Views/Login.aspx");
More info:
When I tried adding
routes.MapPageRoute("Login", "login", "~/Live/Views/Login.aspx");
routes.MapPageRoute("Login", "login", "~/Demo/Views/Login.aspx");
the routes didn't work. I received a 404 error when trying visit http://192.168.0.145/Live/login Not sure what the problem is.
I'm using IIS 7.1 for published versions and whatever Win XP pro uses for debug.
Youre "environments" seem to be sub-directories of the root of the application. Because the first of your three URLs does not contain a second value (e.g. "http://localhost:48060/debug/login") it's not going to be easy to define one route for all three.
If these secondary environments are defined as their own applications then you should be able to use the same route in each, but we would need more details to help you further.
Please describe your situation a little better and I will update my answer with more information.
Turned out to be a configuration issue that m$ forgot to mention. Got it working by modifying my web.config to use runAllManagedModulesForAllRequests
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
I am try to get routing configured on an asp.net 4.0 site running on an IIS6 server.
I am using MapPageRoute and it takes me to the correct page. Problems I have encountered so far:
Extensionless Url Routing
Solved by installing QFE described here Link
Static content such as js, css and images not displaying
Solved using Chris Cavanagh's baseUrl technique described here chriscavanagh.wordpress.com/2008/11/06/aspnet-routing-just-enough-rope/
Relative urls and postback scenarios
NOT SOLVED. For some reason, relative paths are not being interpreted correctly. For example. asp:ImageButton runat="server" ImageUrl="~/images/tree.jpg" is rendering out as and img with src="". I have been able to force it to work by setting the ImageUrl to an absolute path but I can't do this for everything. It is also affecting postback scenarios. Button clicks are taking me from (eg) localhost/website/articles/the-article_description/ to localhost/website/the-article-description which does not exist.
Can anyone help me out with this?
For situations like #3, I have been placing a function there that returns a string to be used as a prefix URL for the production site. So for this part where you have:
mageUrl="~/images/tree.jpg"
adjust it to this:
mageUrl="<%= [YourNameSpace].AppMethod.IsProd() %>/images/tree.jpg"
'AppMethod' is some static class and the IsProd() function returns the prefix necessary to specify the production path if the app is running in production. Otherwise the prefix "~" if the app is running in dev. You can determine if the app is running in production by reading the machine name.
do you have the RouteExistingFiles property set to true?
I've found myself having a requirement to configure log4net based on a file relative to the physical location of the running ASP.NET web application. We like to start the logger as early as possible, so Application_Start seems a proper place. In IIS6, this works fine and has been running for ages, but now we moved to IIS7 and this won't work anymore:
string absolutePath = HttpContext.Current.Request.PhysicalApplicationPath;
because the HttpContext.Current is not available in many global.asax (Application, Session) events. This is old news, we all know it raises the now infamous Request is not available in this context error. We don't want to move back to Classic Mode.
Now, the question is simple: without using HttpContext, is it possible to find the physical location of the currently running web application instance?
Try HttpRuntime.AppDomainAppPath. For more info, read IIS7 Integrated mode: Request is not available in this context exception in Application_Start posted by Mike Volodarsky.
As an alternative answer to my own question, I'd like to add that Server.MapPath() works during the Application_Start event as well. The application domain path would then be equal to Server.MapPath("~"), but it's handier for mapping relative paths, removing the burden of concatenation (what MapPath was meant for to begin with).