I'm running a mobile services instance (C# backend) and besides all the other functionality, I also need to host a few html pages and their respective css files.
Here is what I tried:
If I browse to http://<service-url>/myfile.html I get an 404 error. So I
created a myfile.html file and stuck it in the project root folder. Now, instead of 404, I get a blank page.
I tried going through the ContentController by putting the html file in <project root>\api\Content\Views\myfile.html. When I browse to http://<service-url>/api/Content/Views/myfile.html I get a blank page.
Update Dec, 2015
Now that Microsoft published App Services you should probably use that - create a mobile app and a web app and you're done.
Don't try to hack around with Mobile Services.
It always felt to me that Mobile Services were a half baked solution. It is more a competitor to Parse.com and similar BaaS and was missing a lot of the stuff you'd expect from an Azure service.
Update
The solution below does not work but it does teach you a lot about how the mobile service is built. The reason the solution does not work is that Azure refuses to upload the static files to the mobile service instance.
You start by understanding what is Owin and that mobile services are using one. This post helped me a lot.
Then you look in this link which explains how to build a file server using katana.
Here are short instructions:
Install nuget package Microsoft.Owin.StaticFiles.
Plug into the OwinAppBuilder and instruct it to use Katana's file server just before you run the original (put this in WebApiConfig.cs):
var originalAppBuilder = StartupOwinAppBuilder.OwinAppBuilder;
StartupOwinAppBuilder.Initialize(builder =>
{
builder.UseFileServer("/static");
originalAppBuilder(builder);
}
Create a static folder in your project root, put some files there and browse to <your service url>/static/somefile.html.
Related
I do have an ASP.NET Core 5 Web API project which is currently hosted as an Azure Web App on a Windows App Service plan. Since I have a couple of gigabytes of storage associated with the App Service plan, I want to use 10 GB for an image cache where I store images generated from the API.
Here is some context:
I don't want to use Azure Storage / Blob Storage for this to avoid unnecessary traffic costs and delays. Some images are generated from multiple layers of other images (let's call them intermediate images) and I cache everything.
My caching solution works fine locally, but currently not on Azure.
I want to use 'Remove additional files at destination' when publishing a new version of my API.
The cache will be cleared/invalidated via an API call, not on deployment or app restart.
As I've said, the caching works fine if I run at locally on IIS Express. As far as I know, the Windows App Service plan uses Kestrel for hosting. I'm looking for a storage path within the Azure Web App, where I can create and delete directories + create/read/delete files.
Since the App Service Plan is B1, the App Service plan is running on a dedicated Azure VM, according to the docs: https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans
From https://learn.microsoft.com/en-us/azure/app-service/operating-system-functionality, I've learned that there is a C drive and a D drive as well.
From my web app, I can select Development Tools -> Advances Tools -> Go to see Kudu. When I click on Environment in Kudu, I can see some absolute paths that I've tried to write to without success. I've also tried to access
Environment.GetEnvironmentVariable("HOME")
IWebHostEnvironment.WebRootPath
IWebHostEnvironment.ContentRootPath
"D:\home\site\wwwroot"
"D:\home\"
without success as well.
I also tried to add a virtual directory (since I want to store images in another directory to be able to use the 'remove additional files on destination' option). I also connected via FTP to /site/wwwroot/ where I can see my deployed application.
In the past, I was able to read files from a virtual directory from an ASP.NET Webforms application, but with this ASP.NET Core 5 API project, I didn't have any success mapping relative paths to absolute paths.
My main question is: What absolute path to I need to use in my API project to have create/delete directory permissions and create/read/delete file permission into my Azure Web App?
Okay, I've figured it out. I had some fatal errors when starting the application. It seems that they were related to ApplicationInsights. I removed it completly from the Azure Web Portal and now everything works.
The following path works as a base path D:\\home\\
I want to launch a web api host when launching the application on xamarin, which I will make requests for, but I don’t understand how to connect the web api project and xamarin.forms or is there some other way of debugging the application.
I know that you can deploy the application on the azure service, but I want it to work locally
Those are two different applications.
Xamarin.Forms
Xamarin.Forms is an open-source UI framework. Xamarin.Forms allows developers to build Android, iOS, and Windows applications from a single shared codebase.
WebApi Core
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the . NET Framework.
The first one is deployed on app stores and installed on devices.
The web api is deployed in web servers (like IIS) or on azure, and can be accessed over internet via http calls.
During development, you can build and deploy on your localhost. Check here for setup guidance: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio
You can consume your api from xamarin forms as described here:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/rest
Example:
public async Task<List<TodoItem>> RefreshDataAsync ()
{
...
var uri = new Uri (string.Format (Constants.TodoItemsUrl, string.Empty));
...
var response = await _client.GetAsync (uri);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync ();
Items = JsonConvert.DeserializeObject <List<TodoItem>> (content);
}
...
}
This is pretty simple with Visual Studio 2019/2017.
After creating your Xamarin forms project, add an ASP.NET Core app to your solution; Visual Studio will manage everything. To debug the ASP project, set it as Startup project and click on the beautify Play/Start button and the browser should start and wait for a breakpoint or your stuff ...
You can debug Xamarin and the ASP Web app at the same time.
First we assume that the Web App act as an API endpoint for your app ; so that you will call it to send or request data ...
Then we assume you have a web client to call your endpoint and controllers in your Web app to receive that requests and respond ...
OK all that given, do this:
Right click on the solution in the Solution Explorer
Pick Properties
At the left side of the properties page, select Startup Projects
Multiple startup projects radio box
Action column set Start on every project you want to debug
Then ok and play
Hope this helped.
Useful links
Create an ASP App From the official documentation
Debug multiple projects answered by Max
.
You can run two instances of Visual Studio locally, one for the API project and the other for the Xamarin app.
In addition to Athanasios Kataras's answer, this documentation tells you how to connect to a local web service from the iOS Simulator or Android Emulator: https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services
It's been incredible exhausting for me, after passing a week to deploy MVCForum (Source Code) to my Azure Web App. I've read that it was possible if you selected a different path when publishing, something that I did. But when I tried running, my main app and the MVC Forum were conflicting between them.
I'd like to use Azure's Web Apps instead of Azure's Cloud Services because of the simplicity and the possibility of only uploading the files that have changed. I have seen that it is possible to upload Web Api and MVC in that fashion, but I have not found an example that sends 2 different MVC apps into a same Web App.
Is it possible to do it with 2 different MVC apps? (Note: Areas are not an option, since the MVC Forum Source Code resides on a completely different solution)
Thanks!
Given your comment that you are trying to work with separate deployments:
A Web App under the same name (e.g. myapp.azurewebsites.net) is going to be managed by a single deployment. That is, if you have two github repo's (or two dropbox folders, or two of anything) and try to push up new content from deployment B, you'll effectively wipe out deployment A.
You can certainly have multi-path apps running in the same deployment, but they'd need to be part of a single distribution (e.g. single github repo). Otherwise, you'd need multiple deployment slots (e.g. app-a.azurewebsites.net and app-b.azurewebsites.net).
Maybe you can use virtual directory to upload multiple app projects in single webapp, this article explained it
Create projects
Assign virtual directory
Publish the root project
Set up virtual directory in azure portal
Publish the child projects
Below is the task i have to complete in a few weeks, my question is does anyone know of any tutorials or books which will be of use to me? I also only have little knowledge of C#.
You will design the relevant code in ASP.NET and C# so that you can
deploy a web role on Azure that can:
a) read in a zip file from input on the web page
b) uncompress the zip file which will have an executable, an
arbitrary list of arguments and data files
c) run the executable with the arguments (and hence read in the
data files).
d) store the output logs for access later.
You will test this by running a piece of code that reads in a set of
arguments which correspond to test files.
The executable will then read in the text files and then print them
out.
You will also have to design an appropriate UML to explain how the
different classes you have written interact.
You can deploy your service/role to Azure using Service Management API. Write a module which does the deployment and call this in your web.
Check these links that may help you.
Deploying An Azure Application
Publish Azure WebRole using Installer (like WIX)
About the Service Management API
The Windows Azure Accelerator for Web Roles makes it quick and easy
for you to deploy one or more websites across multiple Web Role
instances using Web Deploy. The accelerator includes a Visual Studio
project template that creates a Windows Azure web role to host one or
more websites.
Azure Tutorial; Be in cloud (Part 3) [Web Role]
Windows Azure and SQL Azure Tutorials - Tutorial 1: Using Windows Azure Web Role and Windows Azure Table Service
Check Azure in Action Book and it's content.
Hope these help you to get an idea that you want to implement.
That's hard homework: Upload a zip file to a cloud based server and run the .exe. Interesting...
Anyway, the Azure SDK is a great place to start. Also scan through Smarx's Cloud Cover shows. They cover pretty much everything.
I have just completed my first aspx/c# project using Visual Web Developer Express and consuming some custom controls and external web services. It runs fine on my development machine.
If I now want to test this on a shared hosting account, do I just upload all the files with the current project structure? Will there be any problem uploading the DLLs to a shared Windows hosting account? Anything I should be aware of or changes to be made to the code? Can anyone recommend a cheap and good provider (this is just for testing - no mssql required yet).
Thanks!
Does visual web developer have a "publish website" menu item under the Build menu?
If you want to pre-compile your site and publish it with all dependencies the easiest way I've found. You can then choose to publish it to either an FTP site or the file system. I usually choose the filesystem and then FTP it up myself to make sure I don't overwrite any config files.
If I'm working on a low volume site for a client and performance isn't a problem, I'll just upload my working directory right up to the server so I don't have to deliver the source code separately and I know they won't loose it.
Oh, and one other thing, if you don't configure it special, I would expect you will have to upload your site to the root directory of your hosting account. GoDaddy does have the ability to specify certain directorys as their own ASP.NET application. If you do that you can put your app in a sub-dir of your choosing.
-Al
It would depend on your website provider. You need to get one that supports the .NET runtime. Once you have that, then you simply upload your code and all should work. I personally use www.godaddy.com. You can see an example ASP.NET site hosted by them at www.chessbin.com.
I hope this helps.
Adam
The hosting companies may vary on what they require, but I would think a simple xcopy deploy would be sufficient for most. Here's a link to one that seems to have good prices (disclaimer: I have never used them)
http://www.reliablesite.net/v3/index.asp