I have an old solution where i get the OWIN context with
var context = httpRequestMessage.GetOwinContext();
from this context I fetch sessionId like this:
httpRequestMessage.Headers.FirstOrDefault(x => x.Key == "SessionId").Value.FirstOrDefault();
Now this works without any problems on my IIS 8.5 but when upgrading to IIS 10 the sessionId is just lost and the key == "SessionId" is not found.
Setup between 8.5 and 10 is identical still it won´t work.
I´ve tried:
Mixing with TLS settings,
mixing with different Session States
Any help is appreciated! :)
Related
After deploying my ASP.NET Core 2.2 application using IIS, sessions, which are codeded using HttpContext.Session aren't working. If I set a session variable, as soon as the request ends, variable is deleted and if I try to access it after with different request, the value of the variable is null. While if I run the app in visual studio everything works.
Don't do that unless you want all cookies to not require consent. To allow the session, you should only add the option Cookie.IsEssential = true in AddSession. This will mark session cookies as essentials.
services.AddSession(options => {
options.IdleTimeout = TimeSpan.FromMinutes(15);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
Read this for more info: https://andrewlock.net/session-state-gdpr-and-non-essential-cookies/
The problem was, that IIS decided that session cookie was not essential and I had an option enabled to require user permission to use non-essiantial cookies. Because I only use essential cookies, I just changed this options.CheckConsentNeeded = context => true; to this options.CheckConsentNeeded = context => false; in Startup.cs
I recently need to use .net core to do SOAP NTLM login.. to my horror.. I realized ,net core does not come with SOAP support.. fumbling around, I came across SOAPCore on nuget package which has SOAP middleware for .net core. My console app interfacing to .net core 2.1 SDK tries to do NTLM login. Below is the codes, very simple.. it's trying to login to Milestone VMS.
<----------codes--------------->
int MAX_BUFFERSIZE = 2 * 1024 * 1024;
string strURL = "http://192.168.51.207/ServerAPI/ServerCommandService.asmx";
BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.MaxBufferSize = MAX_BUFFERSIZE;
httpBinding.MaxReceivedMessageSize = MAX_BUFFERSIZE;
httpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm; //changed Ntlm to Windows also don't help
EndpointAddress endpoint = new EndpointAddress(strURL);
var factory = new ChannelFactory(httpBinding, endpoint);
CredentialCache cc = new CredentialCache();
NetworkCredential ntcc = new NetworkCredential("user", "password", "domain");
cc.Add(strURL, 80, "ntlm", ntcc);
factory.Credentials.Windows.ClientCredential = cc.GetCredential(strURL, 80, "ntlm");
var client = factory.CreateChannel();
Guid guid = Guid.NewGuid();
LoginInfo lo = client.Login(guid, "");
Console.Write("\ntoken=" + lo.Token);
ConfigurationInfo config = client.GetConfiguration(lo.Token);
... //do something
client.Loguout(guid, lo.Token); //logout
<-------------end of code segment------------>
Now, running this in Windows 10 works fine.. it's able to login and get the info needed.. but funny thing is when it runs on Linux.. I installed BASH for Windows 10 and it's Ubuntu 18.04, and have installed .net core 2.1.300.. it gave an http code 401 exception: "The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate, Ntlm'."
I've previously read on Stackoverflow about something quite similar and it was said that .net core 2.1 would resolve it.. I'm already using 2.1.300. Is it still not resolved? or am I doing something wrong?
Another question I have pertaining to this, the "ServerCommandServiceSoap" interface is generated using svcutil.exe from the wsdl file provided by Milestone in their SDK. Now, what is the difference between svcutil.exe and wsdl.exe? I noticed that the proxy class generated isn't the same usi ng these two tools.. using svcutil.exe has an interface class with dependencies on System.ServiceModel, while using wsdl.exe has no interface class and depends on System.Web.Services which is not available in .net core. why is it different when they are ran against the same wsdl document?
Can someone please enlighten me on this? thanks a lot.. :)
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.
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.
I want my MVC3 web application to access %APPDATA% (e.g. C:\Users\MyUsername\AppData\Roaming on Windows 7) because I store configuration files there. Therefore I created an application pool in IIS with the identity of the user "MyUsername", created that user's profile by logging in with the account, and turned on the option "Load User Profile" (was true by default anyway). Impersonation is turned off.
Now I have the problem that %APPDATA% (in C#):
appdataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
resolves to c:\windows\system32\inetsrv instead of C:\Users\MyUsername\AppData\Roaming.
UPDATE: More exactly, the above C# code returns an empty string, so that Path.GetFullPath(Path.Combine(appdataDir, "MyAppName")) prepends the current path to my application name, resulting in c:\windows\system32\inetsrv\MyAppName.
I know I made this work before with the same web application on a Windows Server 2008 R2, and now I'm getting this problem with the same major version 7.5 of IIS on my Windows 7.
I used the same procedure as before: Created a new user, logged in as that user to create the profile and APPDATA directories, then added the application pool with this identity and finally added the web application to this pool.
Any ideas?
Open your %WINDIR%\System32\inetsrv\config\applicationHost.config and look for <applicationPoolDefaults>. Under <processModel>, make sure you don't have setProfileEnvironment="false". If you do, set it to true.
Application Pools - Your application Pool - Advanced settings ...
Process Model - Load user Profile set True.
It Helps me.
Taken from
https://blogs.msdn.microsoft.com/vijaysk/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool-identity/
I experienced the same problem recently. As mentioned by Amit, the problem is that the user profile isn't loaded. The setting is for all application pools, and is in the applicationHost.config (typically C:\Windows\System32\inetsrv\config\applicationHost.config). If you update the applicationPoolDefaults elements as follows, it will work;
<applicationPoolDefaults managedRuntimeVersion="v4.0">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</applicationPoolDefaults>
We've tried this with IIS 7.5, and taken it through to production without problem.
You can automate this if you want;
appcmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.processModel.setProfileEnvironment:"true" /commit:apphost
or if you prefer powershell
Set-WebConfigurationProperty "/system.applicationHost/applicationPools/applicationPoolDefaults/processModel" -PSPath IIS:\ -Name "setProfileEnvironment" -Value "true"
Hope this helps
I am experiencing the same problem. Have you by chance installed the Visual Studio 11 beta? I did recently, and I've noticed a couple of differences in how the 4.0 compatible .dlls for that work with our code. I'm still trying to track down the problem for certain, but I didn't have this problem before that.
Edit:
After comparing the decompiled sources from 4.0 and 4.5 for GetFolderPath (and related), there are differences. Whether they are the source of the problem...I'm not sure yet.
Edit 2: Here are the relevant changes. I'm working on trying both to see if I get different results. [code removed]
Edit 3:
I've now tried calling SHGetFolderPath directly, which is what the .NET Framework ends up doing, anyway. It returns E_ACCESSDENIED (-2147024891 / 0x80070005). I don't know what has changed where I'm getting that in some specific cases, but not in others.
Edit 4:
Since you're getting a empty string, you may want to switch your code to use SHGetFolderPath so you can get the HResult and at least know what exactly is happening.
void Main() {
Console.WriteLine( GetFolderPath( Environment.SpecialFolder.ApplicationData ) );
}
[System.Runtime.InteropServices.DllImport("shell32.dll")]
static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, uint dwFlags, StringBuilder pszPath);
private string GetFolderPath( Environment.SpecialFolder folder ) {
var path = new StringBuilder( 260 );
var hresult = SHGetFolderPath( IntPtr.Zero, (int) folder, IntPtr.Zero, 0, path );
Console.WriteLine( hresult.ToString( "X" ) );
return ( (object) path ).ToString( );
}
The problem is with your IIS settings. The answer is here: Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) returns String.Empty