ASP.NET Core WebSockets on IIS 7.5 - iis

I know the WebSockets are supported only on Windows 8 and higher. But sometimes you just can't upgrade the system in large organization. So I tried implement WebSockets on ASP.NET Core app.
I take NuGet package "AspNetCore.WebSockets.Server" and run as a self-hosted app on Windows 7 and everything works well. But hosting on IIS7.5 on the same machine wont allow me to upgrade HTTP connection to WebSocket. Even if I try to simulate the handshake the IIS simple removes my "Sec-WebSocket-Accept" header.
static async Task Acceptor(HttpContext hc, Func<Task> next)
{
StringValues secWebSocketKey;
if(hc.Request.Headers.TryGetValue("Sec-WebSocket-Key", out secWebSocketKey))
{
hc.Response.StatusCode = 101;
hc.Response.Headers.Clear();
hc.Response.Headers.Add("Upgrade", new StringValues("websocket"));
hc.Response.Headers.Add("Connection", new StringValues("Upgrade"));
// Disappears on client
hc.Response.Headers.Add("Sec-WebSocket-Accept", new StringValues(GetSecWebSocketAccept(secWebSocketKey[0])));
}
await next();
}
I definitely sure IIS7.5 physically can manage WebSockets if they was implemented by developer and that behavior (header removal) looks like a dirty trick from Microsoft

I am afraid you need IIS 8
With the release of Windows Server 2012 and Windows 8, Internet
Information Services (IIS) 8.0 has added support for the WebSocket
Protocol.
https://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support
The new http.sys is the one that can turn a regular HTTP connection into a binary communication for websockets. Although you can implement your own thing, you cannot hook it into http.sys.

Related

SSL based webserver on Windows IoT

I am working on a project which involves gathering some sensor data and build a GUI on it, with controlling of sensors. It has following two basic requirements.
Should be a web based solution (Although it will only be used on LAN or even same PC)
It should be executable on both windows IoT core and standard windows PC (Windows 7 and above)
I have decided to use Embedded webserver for Windows IoT, which seems to be a good embedded server based on PCL targeting .NET 4.5 and UWP. So I can execute it on both environments. That is great! But the problem is this web server doesn't support SSL, I have tried to search other servers and have come up with Restup for UWP, which is also a good REST based web server, but it also doesn't support SSL.
I needs an expert opinion, that if there is any possibility I can use SSL protocol in these web servers. Is it possible that it can be implemented using some libraries like OpenSSL etc? (Although I think that it would be too complex and much time taking to implement it correctly)
Edit
I would even like to know about ASP.NET core on Windows 10 IoT Core, if I can build an application for both windows. I found one example but it is DNXbased, and I don't want to follow this way, as DNX is deprecated.
Any help is highly appreciated.
Late answer, but .NET Core 2.0 looks promising with Kestrel. I successfully created a .Net Core 2.0 app on the PI 3 this morning. Pretty nifty and If you already have an Apache web server, you’re almost done. I’m actually going to embed (might not be the right term) my .Net Core 2.0 web application into a UWP app, rather than create multiple unique apps for the touchscreens around the house.
.Net Core 2.0 is still in preview though.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x
I know this post is pretty old, but I have built the solution which you are asking bout. I’m currently running .Net 5.0 on a Raspberry pi. When you build the .net core web project, select the correct target framework and the target runtime to win-arm. Copy the output some directory on the pi and you will have to access the device using powershell to create a scheduled task to start the web project. Something like this:
schtasks /create /tn "Startup Web" /tr c:\startup.bat /sc onstart /ru SYSTEM
That starts a bat file which runs a powershell command which has the following command:
Set-Location C:\apps\vradWebServer\ .\VradTrackerWeb.exe (the .\VradTrackerWeb.exe is on a second line in the file) - the name of the webapp.
That starts the server. If you have any web or apps posting to the webserver you will need an ssl cert. I used no-ip and let’s encrypt for this. For let’s encrypt to work, you will need an external facing web server and have the domain name point to it. Run let’s encrypt on the external server and then copy out the cert and place it in your web directory on the pi. I then have a uwp program that runs on the pi and when it starts, it gets it’s local address and then updates no-ip with the local address, so the local devices communicating will be correctly routed and have the ssl cert. Side note, my uwp app is the startup app on the device. The scheduled task is important because it allows you to run you app and the web server. The following snip is how I get the ip address and then update no-ip.
private string GetLocalIP()
{
string localIP = "";
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
{
socket.Connect("8.8.8.8", 65530);
IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
localIP = endPoint.Address.ToString();
}
return localIP;
}//GetLocalIP
private async void UpdateIP()
{
string localIP = "";
string msg = "";
var client = new HttpClient(new HttpClientHandler { Credentials = new NetworkCredential("YourUserName", "YourPassword") });
try
{
localIP = GetLocalIP();
string noipuri = "http://dynupdate.no-ip.com/nic/update?hostname=YourDoman.hopto.org&myip=" + localIP;
using (var response = await client.GetAsync(noipuri))
using (var content = response.Content)
{
msg= await content.ReadAsStringAsync();
}
if (msg.Contains("good") == true || msg.Contains("nochg")==true)
{
SentDynamicIP = true;
LastIPAddress = localIP;
}
else
{
SentDynamicIP = false;
}
}
catch(Exception ex)
{
string x = ex.Message;
}
finally
{
client.Dispose();
}
}//UpdateIP

Hosting ASP.NET Core in IIS without Kestrel

Our hosting department is not willing to allow ASP.NET core hosting with Kestrel running or even installing the ASP.NET Core Server Hosting Bundle (AspNetCoreModule).
Is there any alternative to allow ASP.NET core in this situation?
Environment: Windows Server 2012 R2 with latest IIS and .NET 4.6.2.
It is a shared hosting environment and the application(s) must be running in IIS.
You can actually run ASP.NET Core in IIS within the worker process (thus not using the ASP.NET Core Module) by using OWIN.
This is possible due to the fact that ASP.NET Core can be hosted on an OWIN server and IIS can be made an OWIN Server.
Have a look at the following OWIN middleware which shows how to run ASP.NET Core on IIS. For a more complete example, see this gist: https://gist.github.com/oliverhanappi/3720641004576c90407eb3803490d1ce.
public class AspNetCoreOwinMiddleware<TAspNetCoreStartup> : OwinMiddleware, IServer
where TAspNetCoreStartup : class
{
private readonly IWebHost _webHost;
private Func<IOwinContext, Task> _appFunc;
IFeatureCollection IServer.Features { get; } = new FeatureCollection();
public AspNetCoreOwinMiddleware(OwinMiddleware next, IAppBuilder app)
: base(next)
{
var appProperties = new AppProperties(app.Properties);
if (appProperties.OnAppDisposing != default(CancellationToken))
appProperties.OnAppDisposing.Register(Dispose);
_webHost = new WebHostBuilder()
.ConfigureServices(s => s.AddSingleton<IServer>(this))
.UseStartup<TAspNetCoreStartup>()
.Build();
_webHost.Start();
}
void IServer.Start<TContext>(IHttpApplication<TContext> application)
{
_appFunc = async owinContext =>
{
var features = new FeatureCollection(new OwinFeatureCollection(owinContext.Environment));
var context = application.CreateContext(features);
try
{
await application.ProcessRequestAsync(context);
application.DisposeContext(context, null);
}
catch (Exception ex)
{
application.DisposeContext(context, ex);
throw;
}
};
}
public override Task Invoke(IOwinContext context)
{
if (_appFunc == null)
throw new InvalidOperationException("ASP.NET Core Web Host not started.");
return _appFunc(context);
}
public void Dispose()
{
_webHost.Dispose();
}
}
Yes, you could use WebListener web server instead of Kestrel. WebListener only works on the Windows platform but since that is where you are running, it's an option for you.
WebListener however does not rely on IIS as a reverse proxy, in fact WebListener can't be used with IIS or IIS Express since it's not compatible with ASP.NET Core Module. But it does give you a non Kestrel option for hosting ASP.NET Core on windows.
You can learn more about it here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/weblistener
Prior to ASP.Net Core 2.2
If you must host in IIS and you don't want to use Kestrel and you are running on windows, then there are no options. On Windows, you either host with WebListener without IIS or you host with Kestrel using IIS as a reverse proxy. Those are your only two options currently on Windows.
Update: ASP.Net Core 2.2 or later Starting in ASP.Net Core 2.2 there is now support for running ASP.Net Core In Process in IIS. Under such a configuration Kestrel is not used. To learn more see In Process Hosting Model on the Microsoft Docs site or this blog post https://weblog.west-wind.com/posts/2019/Mar/16/ASPNET-Core-Hosting-on-IIS-with-ASPNET-Core-22

How to programmatically open the Bluetooth settings in iOS 10

I'm trying to access the Bluetooth settings through my application using swift.how can access bluetooth setting?
Xcode version - 8.0
swift - 2.3
iOS - 10
func openBluetooth(){
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting
let app = UIApplication.shared
app.openURL(url!)
}
Swift 3.0: working up to iOS 10
Note: This URL is "private API". The app will be rejected by App Store reviewers if used.
You will not be able to use the solution by #Siddharth jain. The Problem: The app will be rejected by Apple with a warning that you should never use non-public APIs anymore. Otherwise, you could risk your developer program.
As far as I know, all you can do is open the iPhone settings in general (or get lead to your app settings if there are some. To do so you need the following code
guard let url = URL(string: UIApplication.openSettingsURLString) else {
// Handling errors that should not happen here
return
}
let app = UIApplication.shared
app.open(url)
By this, you will always get a URL you can use without any problems with apple review.
Until now you cannot access to bluetooth settings from your app from iOS 10.
you can see the following link to keep your mind at peace.
https://forums.developer.apple.com/message/146658#146658
Opening the Settings app from another app
Now that iOS 15 seemed to have broken auto-reconnect for known Bluetooth devices (other than audio gadgets), it's extremely annoying. If someone finds a solution, App Store-safe or not, I'm all ears.

Just created Azure Mobile App service calls return http 400 error

Here's what I'm doing.
Install latest Azure SDK (by the date)
Open Visual Studio 2013
Create a new Azure Mobile App project. The simple service is created with TodoItem DataObject and 2 simple controllers - TodoItemController and ValuesController
Do not change anything
Start the project
The service is started and hosted in local IISExpress on url http://localhost:50993/ (the port may vary).
The "This mobile app is up and running" web page is opened in the browser. But http 400 error is returned when I try to invoke some GET-actions: for example http://localhost:50993/api/values or http://localhost:50993/tables/TodoItem.
Any ideas? Is something wrong in my environment or is that me doing something wrong?
Thanks.
I guess you can opt out of version checking by setting a value of true for the app setting MS_SkipVersionCheck. Specify this either in your web.config or in the Application Settings section of the Azure Portal.
This generally happens when you don't add a ZUMO-API-VERSION header to the request. This is required when making requests from a REST client, but the mobile client SDKs add the header automatically.
To fix, add the header ZUMO-API-VERSION with value of 2.0.0.
To learn more, see https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-client-and-server-versioning/.
Adding
http://localhost:50993/tables/Location?ZUMO-API-VERSION=2.0.0
at the end will do the trick.

SignalR works partially on Remote Server IIS 7.5. Works fine in VS 2012. MVC4

There are similar questions but mine is a peculiar case. My signalr application works only partially on IIS 7.5
My SignalR implementation is working only partially.
I'm using SignalR 1.3, .Net Framework 4.0. MVC4
and IIS 7.5 on Wondows 2008r2
The following lines of code do execute. I get an alert and I'm able to send a message to all the clients.
$.connection.hub.start().done(function () {
alert("hi signalr started")
$('#sendmessage').click(function () {
chat.server.send($('#displayname').val(), $('#message').val());
$('#message').val('').focus();
});
});
But
public override Task OnConnected()
{
Clients.Caller.getClientName();
return base.OnConnected();
}
This method is failing to call client method getClientName().
chat.client.getClientName = function () {
//a method that the onConnect method calls to get the user's name
alert("hi");
};
I don't get an alert in this case.
Everything is working fine if I run it on VS 2012.
Please help
Did you add support for extensionless URLs?
http://support.microsoft.com/kb/980368
Also note you will need to update your web server to IIS 8.0 to get WebSockets support.
For further details, see the Supported Platforms doc"
http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/supported-platforms

Resources