Where do I add a static html file "mycoolpage.html" to a MVC4 project so it will be served when requesting "mysite.cloudapp.net/mycoolpage.html" when deployed to azure?
I've tried adding it to the project and setting up routes like
routes.IgnoreRoute("{resource}.html");
and tried returning it from a controller using the following route
routes.MapRoute(
"mycoolsite.html",
"mycoolsite.html",
new { controller = "Home", action = "Coolsite" }
);
Have you tried: routes.IgnoreRoute("*.html"), with the file in the root folder of your MVC site?
(From: Getting MVC to ignore route to site root)
Related
I have .net core web API PROJECT. I want to put some static images in this project.I have below code in start up file
var provider = new FileExtensionContentTypeProvider();
// Add new mappings
provider.Mappings[".myapp"] = "application/x-msdownload";
provider.Mappings[".htm3"] = "text/html";
provider.Mappings[".image"] = "image/png";
provider.Mappings[".png"] = "image/png";
// Replace an existing mapping
provider.Mappings[".rtf"] = "application/x-msdownload";
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), #"MyStaticFiles")),
RequestPath = new PathString("/StaticFiles"),
ContentTypeProvider = provider
});
when I run or deployed this web project, i have checked under it has StaticFiles folder has test.png
when I browse for test.tt/StaticFiles/test.png, or test.tt/wwwroot/StaticFiles/test.png or test.tt/wwwroot/StaticFiles/images/test.png
browser is not loading that image, it is displaying white page, where I check on network console of by F12,it is delivering response of type document and json.
My problem is image is not displaying, i have tried more images but not helpful.I am sure there is image,folder in my path.
can you tell how if I browse test.png,direct hitting path to get static file .net core WEB API images?
By default, static files go into the wwwroot in your project root. Calling app.UseStaticFiles(), causes this directory to be served at the base path of the site, i.e. /. As such, a file like wwwroot/images/test.png would be available at /images/test.png (note: without the wwwroot part).
I'm not sure what in the world you're doing with the rest of this code here, but you're essentially adding an additional served directory at [project root]/MyStaticFiles, which will then be served at /StaticFiles. As such, first, test.png would have to actually be in MyStaticFiles, not wwwroot, and then you'd access by requesting /StaticFiles/test.png.
However, there's no need for this other directory. If you simply want to add some additional media types, you can do that via:
services.Configure<StaticFileOptions>(o =>
{
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Add(".myapp", "application/x-msdownload");
// etc.
o.ContentTypeProvider = provider;
});
And then just use:
app.UseStaticFiles();
Nothing else is required.
Within a MVC 5 Webapi project, I am trying to do a GET request via jquery using URL 'api/controllerName'. The web application is hosted under Default Website and the root of the webisite is "localhost/myApp".
The route 'api/controllerName' gets translated to 'localhost/api/controllerName' instead of 'localhost/myApp/api/controllerName' throwing 404 Not found Error.
This has to do something with IIS 8.5 and MVC 5 routing, because:
The Same setup works well on IIS 7.5
The same set up works well on IIS 8.5 if i do not use a virtual directory and host the application directly at Default Web Site.
My Global.asax.cs's RegisterRoutes Method looks like below
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
I figured this out. Apparently, IIS 7.5 worked fine with the bare route 'api/controllerName' but IIS 8.5 needed a fully qualified route created using #Url.RouteURL utility with RouteName as "DefaultApi".
i replaced the URL with
'#Url.RouteUrl("DefaultApi", new { httproute = "", controller = "controllerName"})'
and it worked like a charm (on both IIS 7.5 and IIS 8.5).
I'm running self hosted Nancy web application on Owin and have troubles with static content.
Let's say my application runs from this folder:
c:/myfolder/
My Views are in here:
c:/myfolder/Manager/Views/
so in my browser I can go to http://localhost:85/Manager and my page loads.
I simply can't make it to serve static content though, all my files are in /Content folder, I tried to place it both to /myfolder and /Manager folder with no luck.
Neither http://localhost:85/Manager/Content/css/styles.css nor http://localhost:85/Content/css/styles.css urls work
How do I get it to work?
Fixed the problem by adding these lines of code to Startup :
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
...
var options = new FileServerOptions()
{
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem("/Path/here")
};
app.UseFileServer(options);
If I specify DefaultView like this, it works on my local IIS express, but not when deployed to IIS:
[DefaultView("Login.cshtml")]
public class SiteLoginService : EnshareServiceBase
{
}
My Views folder contains Login.cshtml.
It works as expected when running locally on IIS express, but will render the snapshot view when deployed on IIS.
After changing to full path, it works also in IIS:
[DefaultView("/Views/Login.cshtml")]
public class SiteLoginService : EnshareServiceBase
{
Is this by design or is there any other way how to configure ServiceStack to look into the Views folder also when deployed in IIS?
I've deployed a MVC3 application to a win2003 server with .Net4.0 installed . I've configured wildcard mapping for application as described here . Also i did it before for other mvc3 applications on the same server before . I'm sure that the IIS configurations of both mvc3 applications are same.
When i hit the default home page of the default route, it works, but other controllers and actions gives 404. I can't figure out a way for 2 days . Any help will be great.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults );
Make sure that ASP.NET 4.0 is properly registered with IIS 6.0
c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i
and that it is enabled:
Verify below items in IIS
Home Directory tab -> Configuration. Under Wildcard application maps,
1.the entry aspnet_isapi.dll has been added
2."verify file exists" checkbox should be in unchecked state