ServiceStack renders Snapshot views instead of Razor views when deployed on IIS unless fullpath to views is specified in DefaultView - iis

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?

Related

mapbox files pbf blocked IIS server

PBF (street map mapbox vector files) files are not allowed to be served /downloaded from IIS (2008 R8) and I need them to be.
The background
PBFs are served OK when using the react development server
//Startup.cs
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
These files will appear on the map correctly.
However when deploying the .NET Core app to IIS with
ASPNETCORE_ENVIRONMENT = production
set. These files are essentially blocked.
I have added the MIME type
I believe this is an IIS thing as like I say, on the react server in development they load fine.
Any clues as of why they still won't download?
Thanks
Basically IIS virtual directories aren’t supported in .net core. Due to the way .net core projects are served in IIS using a reverse proxy. So in the startup.cs file, do something like this:
// Configure the virtual directory
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(#"\\Server\Directory\.."),
RequestPath = "/NameOfDirectory",
ContentTypeProvider = provider,
OnPrepareResponse = (context) => {
if (!context.Context.User.Identity.IsAuthenticated) {
context.Context.Response.Redirect("LoginPage");
}
}
});

Azure does not see Index.cshtml

I'm trying to publish my ASP.NET Core application on Azure service. This works, but when I try to use the application functionality, I get the message
Your App Service app is up and running.
Moreover, in my wwwroot folder I don't have any .html files. I only have an Index.cshtml file, which is located in the Views/Home-folder in my application, all another files are .css, .js, etc.
When I run the application in Visual Studio in Debug mode, immediately opens the page in browser that was generated from Index.cshtml. But after the application is published in Azure, this does not happen.
What can I do to make Azure see Index.cshtml?
AFAIK, a default route would be added to Configure method of your Startup.cs file as follows:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
I also created my .Net Core 2.0 MVC application to check this issue, it could work as expected on local side and my azure web app.
Moreover, in my wwwroot folder I don't have any .html files.
Views under Web Application and Web Apllication MVC would be compiled into {your-webapplication-assemblyname}.PrecompiledViews.dll, you could leverage ILSpy to check your DLLs.
For your issue, I would recommend you clear the web content in your web app via KUDU, or modify the publish settings and choose Remove additional files at destination under File Publish Options, then redeploy your application to Azure Web App to narrow this issue.
Are you finding index.cshtml in your web package? In case if you get index.cshtml in your final web package, you may need to add index.cshtml file type to the following in..
..YourAzureWebApp --> Application Settings --> Default Documents
I found out what the problem was. There are two types of applications, as presented below in the picture: Web Application and Web Apllication MVC. I worked with the second type of application. When I selected the first type and published the application, Azure immediately found the required index.html. I just had to choose Web Application.
But why does not it work with the second type of application (Web Apllication MVC)? I still do not know the answer to this question.
2 cents from my side as I just stuck for a while with this.
The problem was that yesterday I'd been playing around with deploying to Ubunut / Ngnix and today I decided to try Azure.
BUT I forgot to comment (disable) the following lines in my Startup:
//for nginx server
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
and that costed me almost half of the day to find the issue.
I also put the routing in the following way
app.UseStatusCodePages();
app.UseAuthentication();
app.UseMvc(routes => {
routes.MapRoute(
name: "default",
template: "{controller=Pages}/{action=Index}");
});
Now looks like it works on Azure :)

IIS Virtual directory creates path issue

I am using VS 2013 and MVC5
To host the application in IIS, i have used Properties-> Web ->Servers ->Local IIS and clicked on Create Virtual directory.
So this created a VD for "MyPortal"
But now i have a path problem.
I have an api controller in my application.
When i was using VS development server it was being accessed using the url : localhost:1553/api/menuapi and the data was getting accessed correctly.
But once it is hosted to IIS, it stopped working.
When checked, it is trying to fetch the data from url i.e :
localhost/api/menuapi and it gives a 404 error.
But actually the api is fine and the data is accessible from the url :
localhost/MyPortal/api/menuapi
Why and how is this path problem created?
The below is how i am doing the api call :
1. In javascript file :
$http.get('/api/menuapi/' + menuid).success(function (data) {});
Please suggest if any alternatives.
The problem is that your javascript will only works if the application is deployed on the top level of the webserver (/), as you are using an absolute url.
If your javascript is executed at the top level of your application, you could just change your url as relative:
$http.get('api/menuapi/' + menuid).success(function (data) {});
but if your javascript in a view, a better approach would be to retrieve the proper full url with:
#Url.Content("~/api/menuapi/")
like:
$http.get('#Url.Content("~/api/menuapi/")' + menuid).success(function (data) {});

Nancy on Owin doesn't serve static content

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);

Add Static HTML file to Root of Azure MVC App

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)

Resources