Use last interactive login profile to connect to Azure Analysis Service with Adomd client - azure-analysis-services

I successfully connected to my org AAS database with Adomd .NET client library
using Microsoft.AnalysisServices.AdomdClient;
Console.WriteLine("Starting program...");
AdomdConnection adomdConnection = new AdomdConnection("Provider=MSOLAP;Data Source=asazure://<OrgAAS>;Initial Catalog=<DataCube>;");
adomdConnection.Open();
foreach (CubeDef cube in adomdConnection.Cubes)
{
Console.WriteLine(cube.Name);
foreach (Dimension dim in cube.Dimensions)
{
Console.WriteLine(dim.Name);
}
foreach (Measure measure in cube.Measures)
{
Console.WriteLine(measure.Name);
}
}
Console.WriteLine("Closing program...");
adomdConnection.Close();
However, it keeps prompting me to login every time I launch the program (I only need to select the profile). According to this document https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-connect, Integrated Azure Active Directory authentication will use credential cache if available, but it seems the program didn't cache the credential when I login.
Can I cache the credential so that the prompt windows doesn't appear and prompt me to select the profile everytime I launch?
Also, can I use this set up for my server? Can I set up something like Device code Authentication flow in here https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows?

Related

owin active directory token validation random slowness and error

I am facing some random authorisation problem when using following code to authenticate against ad active directory (I have a web api).
I believe this code will send a validation request to our azure active directory, but randomly we got validation error and some times it can take a while to get validation result back.
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = Constants.AzureActiveDirectoryTenant,
TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
// These values will be checked against what is received in the access token.
ValidAudiences = Constants.AzureActiveDirectoryValidAudiences
}
});
Is it possible to understand why validation failed? Also about the speed, is it possible to create some custom method to cache a token on my web site? So I don't need to validate every request to AD all the time.
You can try the Microsoft.Owin.Diagnostics nuget package to check the logs.
Alternatively, for a remote debug:
In Cloud Explorer in visual studio, find you web app and select "Remote Debugging."
Then publish your site in Debug mode.
In the portal, enable it by going to Application settings > Debugging > Remote Debugging > On

Signalr send message from browser to .net client on the same machine

We need to communicate a native application with a web application.
We think to use signalr to send the message/command.
The pipeline would be:
User clicks to make an action.
Javascript (with signalr) send a message to a server in azure.
The server re-send the message a specific client. It must be the client installed on the same machine.
Once the result is completed, NET sends the resulting reverse.
The matter is, How I can find client from the same machine in the signalr Server?
The organization in our system is:
There is center/gym.
Every center has staff who can login.
We could identify client at the same center with some file configuration. Saving our key center, for example. But, in a center, could there are more than one.NET client installed on the different computer.
We think to use the private IP of the computer to make a key on the signalr server.
var ips = [];
var RTCPeerConnection = window.RTCPeerConnection ||
window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
var pc = new RTCPeerConnection({
// Don't specify any stun/turn servers, otherwise you will
// also find your public IP addresses.
iceServers: []
});
// Add a media line, this is needed to activate candidate gathering.
pc.createDataChannel('');
// onicecandidate is triggered whenever a candidate has been found.
pc.onicecandidate = function (e) {
if (!e.candidate) { // Candidate gathering completed.
pc.close();
console.log(ips);
return;
}
var ip = /^candidate:.+ (\S+) \d+ typ/.exec(e.candidate.candidate)[1];
ips.push(ip);
};
pc.createOffer(function (sdp) {
pc.setLocalDescription(sdp);
}, function onerror() { });
This data can be obtained in .NET client without a problem. But in javascript, the previous code works regularly. In some PC, it only returns ipv4. And in Mozilla it doesn't work.
How can we identify both clients? Do You know another way to reach the goal?
Thanks,
Finally, we didn't find a good solution filtering ip adress.
We did the as follow:
We used URI schema to launch our app. URI Schema windows
Public Class RegistrarURI
Const URI_SCHEME As String = "xxx"
Const URI_KEY As String = "URL:xxx"
Private Shared APP_PATH As String = Location.AssemblyDirectory() ' "C:\Program Files (x86)\xxx.exe"
Public Shared Sub RegisterUriScheme()
Using hkcrClass As RegistryKey = Registry.ClassesRoot.CreateSubKey(URI_SCHEME)
hkcrClass.SetValue(Nothing, URI_KEY)
hkcrClass.SetValue("URL Protocol", [String].Empty, RegistryValueKind.[String])
Using defaultIcon As RegistryKey = hkcrClass.CreateSubKey("DefaultIcon")
Dim iconValue As String = [String].Format("""{0}"",0", APP_PATH)
defaultIcon.SetValue(Nothing, iconValue)
End Using
Using shell As RegistryKey = hkcrClass.CreateSubKey("shell")
Using open As RegistryKey = shell.CreateSubKey("open")
Using command As RegistryKey = open.CreateSubKey("command")
Dim cmdValue As String = [String].Format("""{0}"" ""%1""", APP_PATH)
command.SetValue(Nothing, cmdValue)
End Using
End Using
End Using
End Using
End Sub
End Class
In an Azure WebApp we launch a SignalR Server. This server will send data from our .NET app to Chrome.
To achive that, when the web is loaded, we connect to the signalR server. To build de uri, We send the connectionId from Javascript client to the .NET Client.
Then, when the native process is completed. .NET client send the information to signalR server, and this server mirrored the data to javacript client using the connectionId.
To avoid launch some instance of our native app, we use IPC channel to send data to one instance to the previous and closind the new one.
Link to source Blog source

Apple Push Notifications on Windows Server 2008 not working

I'm stuck and I hope somebody here will help me.
For a few days I'm trying to send apple push notifications from windows server 2008. But nothing is send or received. In fact, I've moved everything to simple mvc application so it can be debug easier and I've noticed that it hangs when I try to force sending the push notifications (on push.StopAllServices(true); )
They were working (and still are) from windows server 2012R2 with the same approach to send notifications so I guess the certificates and code are fine.
I'm using windows service & push sharp to send notifications. target framework: 4
The test project is MVC 2.0 target framework 4
I've installed asp.net 4.5 on the server
I've installed certificate via mmc in Personal (the private key is available, granted permission for IUSR and IIS_USRS) and Trusted Root Certificate Authorities.
Port 2195 is open
Here's the code:
private void Initizalize()
{
push = new PushBroker();
//appleCert is path to my .p12 certificate on disk.
var cert = new ApplePushChannelSettings(false, appleCert, "***");
//I've read somewhere that it was helpful to force send notifications. Well, in my case it's not.
var settings = new PushServiceSettings();
settings.AutoScaleChannels = false;
settings.Channels = 3;
settings.MaxAutoScaleChannels = 3;
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
push.RegisterAppleService(cert, settings);
}
public void SendPush()
{
Initizalize();
var token = hard coded token that exists;
var output = "msg";
push.QueueNotification(new AppleNotification()
.ForDeviceToken(token)
.WithAlert(output)
.WithBadge(1)
.WithSound("default"));
push.StopAllServices(true);
}
It raises event "OnNotificationSent", nothing else.
One more thing that may be important. Sending and receiving push notifications was and is working from windows server 2012 but it's windows azure virtual machine so installing the certificate was different.
Any ideas?
Even the information that it cannot be done will be helpful!
edit:
One problem solved:
Apparently you need to have reference to NewtonSoft.Json in order to call StopAllServices. It doesn't hang now but nothing is received by the device.
Looks like on Windows Server 2008 apns certificates private key must have granted permission for user that wants to use it.
As I wrote before I've granted it for IIS_USRS but that's only for applications running under IIS. And since I was using windows service it wasn't working.
So what I did was check user for windows service (Services -> Log On As) and granted permission to certificates private key for this user.

Directory.CreateDirectory failed on Remote Server

I am working on a small project, in asp.net mvc3, that would copy the deployment files from a local drive to a share drive on a window server 2008 R2 server. I am connected using WMI, and the connection is successful. However, I tried to create a folder, and I receive the message "Logon failure: unknown user name or bad password." Here is a sample code:
bool isConnected = false;
options.Username = user.Name.Trim();
options.Password = user.password.Trim();
mScope = new ManagementScope("\\\\xxx.xxx.xxx.xxx\\root\\cimv2", options);
mScope.Connect();
if (mScope.IsConnected == true)
{
//I've gotten to this point. Then, the code below throw the exception
Directory.CreateDirectory(#"\\\\xxx.xxx.xxx.xxx\Tester\shareFile.txt");
isConnected = true;
}
I'd like to know what am I doing? Is that the right way of doing it?
it is the correct way however it will be the current user you are trying to access that gets passed to the remote computer to create the directory. The management scope at this point has nothing to do with Directory.CreateDirectory. These are 2 different "worlds". you do give the creds to ManagementScope but this has no affect on Directory.CreateDirectory. you could use impersonation to do what you are wanting to:
How do you do Impersonation in .NET?
it is unclear though if you are doing this in ASP.NET/MVC or a different platform. your tags indicate ASP.NET MVC but not your main question.
remember, if you are using ASP.NET/MVC, the credentials of the app pool are being used to perform such actions.

Network Connected Printer not available in ASP.Net Application

I have an ASP.Net 4.0 web application running on IIS 7.5, I can get the list of installed printers using System.Drawing.Printing.PrinterSettings.InstalledPrinters command and assign each report in the application to any printer listed above!
There might be some Network Connected Printers on the server all set with full privilege to the application's user account, everything works perfect until the application's user account logs off the windows, at this point System.Drawing.Printing.PrinterSettings.InstalledPrinters returns only local printers, no Network Connected Printers are listed!
I've tried to impersonate the ASP.Net process to the user with access to Network Printers in following ways, yet no success:
I configured the application pool Process Model to run as a
specific user identity.
I impersonated the Application's identity to specific user in
Web.Config:
<identity impersonate="true" userName="user" password="pass"/>
And finally implemented impersonation in code using advapi32.dll API
In all of the methods above, the WindowsIdentity returns the true username when printing:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
But it looks like that impersonation is not the issue here, the moment the user logs off, all Network Connected Printers are gone!
Does anybody know how to resolve this? Is there any way to access Network Connected Printers even when the user is not logged in?
Network Connected Printers, Shared Folders and Map Drives are only accessible when user logs into the OS, they are barely a shortcut to some network resources, all disconnected and are inaccessible when the corresponding user logs off!
Using System.Printing.PrintServer and the GetPrintQueues method, you can get the collection of print queues that the print server hosts:
PrintServerUNCName is the UNC name of the corresponding server, as in \\MyServerName
var printers = new PrintServer("PrintServerUNCName").GetPrintQueues()
.Where(t =>
{
try { return t.IsShared && !t.IsNotAvailable; }
catch { return false; }
})
.Select(t => t.FullName)
.ToArray();
try following links that might help. You have to add printer on your server by name and access the printer using the name rather UNC.
Printing from ASP.NET to a network printer

Resources