Launch one more instance of same UWP app from first app - c#

My primary concern here is to know how to launch another instance of my UWP app from the same app itself, some code snippet or documentation link would be helpful.
Below are the changes suggested by different links, but didn't found any thing concrete:
Appraoch:
Research suggest that we can launch multiple instance of the same UWP application by setting the package.appxmanifest file with flag SupportsMultiInstances to True. Link here
<Application Id="App"
...
desktop4:SupportsMultipleInstances="true"
iot2:SupportsMultipleInstances="true">
...
</Application>
Extension
We can set the uap:FileTypeAssociation for these apps and later run the instance of the app which we wish. But these are already build files and I need to open new instance at runtime from my uwp app.
URI:
One more way was to open store app using URI.
var uriToLaunch = "testapp-mainpage://";
var uri = new Uri(uriToLaunch);
bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
Now based on this, the way I wish to launch second or another instance of my app is something like below:
Suppose I have an UWP app which have first view to select type of user from dropdown having Agent, Owner and GuestUser. based on that I show list of House properties to user on next page.
Now I would like to have the functionality where, when user press and hold on a house property card then the details to purchase it and other booking page(s) are visible on another instance(where selecting the type of user and selecting the house property is skipped). while if user just click once (not long-press) on a house property card then it will open in the same instance.
SideNote
I am not looking for MultipleView where we show independent part of your app in separate window.

Related

How to restrict a website to get access to a specific path through IIS?

I'm looking for a way to restrict a website served by IIS so that the website can get access to the specific folder or drive not more, let me illustrate it.
Imagine I have two websites A and B served by IIS, you can put following code in code-behind of both websites:
string windowsPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows)
string path = windowsPath + #"\Microsoft.NET\Framework";
var directories = Directory.GetDirectories(path);
I need a way through IIS to restrict website A not be able to get access to the mentioned directories and only website B be able to do that. In other words I want to restrict read access.
I suppose it should have a simple solution because it's what hosting servers deal with. It's obvious that you can't put a piece of code in your website in a web hosting server and simply get access to list files name located in drive C of the hosting server.
How can I achieve that?
After researching a lot I found the solution, I thought it might be useful for ones who will stumble upon this matter later, so I documented the solution.
Note:
From IIS 7.5 on, you have more access on user who is running a website.
Every application pool you make, creates an internal user which is hidden and is known as AppPoolIdentity.
The goal:
Imagine We have two websites A and B, we also have a folder named SecurityTest located in D:\Temp, there are 6 folders inside it under the names 1 to 6, we consider to allow website A get the name of the folders inside SecurityTest while we tend to prevent website B to do that.
Step 1:
Firstly, create a website through VisualStudio, I put a server side button in the form, I consider to get name of folders in the specified path (say D:\Temp\SecurityTest), So here's the code I place in code behind to be triggered when the button is clicked:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = string.Empty;
string path = #"D:\Temp\SecurityTest";
var directories = Directory.GetDirectories(path);
for (int i = 0; i < directories.Length; i++)
{
string fileName = Path.GetFileName(directories[i]);
Label1.Text += fileName + "<br />";
}
}
Step 2: Now let's deal with IIS. Add two websites (or applications) to the IIS, name them A and B, the physical path for both are the same, only change port number, for instance set 81 as port number for website A and 82 for website B. Note that new application pool is created by default with the same name of your website (if you create a new application instead of new website, you should create a new application pool by yourself).
Step 3: Now in the Connections pane, click on website A, from middle pane, double click on Authentication located in the IIS category. Then click on Anonymous Authentication, after that from 'Actions' pane at the right side, click on Edit.
Now select Application pool identity and click on OK. By following these steps you chose AplicationPoolIdentity user as the user who handles website A. Follow these steps for website B.
Step 4: Go to the pathD:\Temp, right click on the folder named SecurityTest, on the Security tab, on the Group or user names category, you can see users listed who have access to the folder, these users are granted permission at the creation time by default. You might see more or less though but the point is that you should add website A ApplicationPoolIdentity user and remove all other users, so remove Users which gives access to all users, after that remove Authenticated users from the list too.
Keep in mind that you can't simply remove these users, you should Disable Inheritance first. here's the steps to achieve that:
Since you tend to allow website A to get directories, you need to add the user corresponding to the website A, now you need to follow the next step.
Step 4-1: On the same dialogue, click on Add to add new user, from here you can't find the user related to the website A since it's a hidden and internal (and virtual) user, I mean the AppPoolIdentity user for website A. You should type the name on the following pattern:
IIS APPPOOL\<app_pool_name>
So for website A I should type IIS APPPOOL\A, click on Check Names to make sure whether the user exists or not, finally press OK button.
Step 4-2: To prevent other users to get access to the webite A, click on Advanced button, click on Disable inheritance, when you encounter the warning message, select the first option (Convert) preferably, then press OK to close the dialogue.
Now in Security tab, click on Edit button to change permissions. Here you can remove users you don't need, like Authenticated Users and Users. From now on both websites A and B won't be able to get folders name.
Now get back to IIS panel and click on website A in the left Pane, then click on Browse *:81 (http) link, you can see the website A on your browser, do the same for website B to open it in the browser. When you click on button in website A you can observe a list of folders from 1 t 6 while you get following error when you click on the button to get directories on the website B.
Access to the path 'D:\Temp\SecurityTest' is denied.
That's all you need to do.
If you understand how pipeline work, you would know that we can only filter permission based by injecting module. So there are few things we can do with IIS configuration.
Asp.net application activated under IIS worker process with Application pool identity. Since Site A and Site B used different managed service account. You could remove IIS apppool\A's permission to prevent site A from reading folder.
Since read permission for application pool identity to access windows\microsoft.net is necessary when activating worker process. It is not recommended to restrict the permission

Check if custom uri is valid

So i'm opening a standalone Unity app from a UWP store app. In my UWP app I use the unity WSA class to launch the custom uri I created.
Example:
In the register I created a custom uri called test:
In UWP app c# I use:
string uri = #"test:";
// Launch the URI
Launcher.LaunchUri(uri, true);
This works fine. The app launches. However if the app does not exist it pops up a dialogue to ask me with what I want to open it. Can I check this also while launching? So if the user has the app not installed I give the user feedback? I tried pretty much every class available for Unity and uri's etc. None of them do what I need. I had high hopes for a few, but all they did was tell me if the URI i entered are valid uri formats, rather then checking if it can actually open the app.
EDIT: Also, what's the difference between Launcher.launchURI and Application.OpenURL?
Application.OpenURL opens a url in the default browser, while Launcher.LaunchUri starts the default app associated with the specified URI.
And no, from the UWP app you just can’t query the system whether the URI is registered or not, there is no such API.
And LaunchUri just returns false if no app is launched, but at that time an error dialog is already prompted, so checking the return value of LaunchUri is not a solution either.

Find out the launch points of active IE instances of windows

We have an application that runs as service on windows. The service periodically checks for active Internet Explorer instances using SHDocVw.ShellWindows(). With this, we are able to capture the URL in each of the IE instances.
My Question:
Is it possible to find out how the webpage in each of these IE instances were launched. For example -
Did user type in url in IE to load the webpage?
Did the user select the link from another IE tab to launch ?
Did the user launch IE instance from another desktop application like outlook etc
Thank you.
The closest thing I could find to your specific requirement was this also check out the part 2 of the same blog where some edge cases have been discussed.
The part 1 of the blog talks about a registry key named TypedURLs (path: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs) which can be found in the registry editor, the rules of updation of this key are like this:
If a link is copied and pasted from a web page to the URL address bar and the user hits enter, this will also populate the key, as this is akin to physically typing in the entire address. If an invalid address of a webpage or resource that cannot be located is entered, the key will not be populated until either the connection or the request is completed (whether it succeeded or failed). If IE’s Stop function is selected before the connection is finished or the resource is located, the key will not be populated.
It is important to note that websites visited with the browser via hyperlinks, redirects, the IE Favorites menu or the user’s home page will not populate this key. Also, when a user selects to delete their browsing history using IE’s built-in function, this key is cleared.
Hope it helps!

Resume, instead Restart, app using URI Launcher

I'm trying implement Facebook Login using the Facebook C# SDK but I'm having an issue returning back to the app when a login has been successful.
I have followed all the steps in this tutorial but i'm having an issue.
I have created a custom UriMapper that should go back to the MainPage.xaml when launched.
public override Uri MapUri(Uri uri)
{
if (uri.AbsoluteUri.Contains("/Protocol?encodedLaunchUri=msft"))
{
return new Uri("/MainPage.xaml", UriKind.Relative);
}
return uri;
}
My problem is the page refreshes and all my data in forms and text boxes gets removed.
Is it possible to "Resume" an app via URI instead of restarting it?
I've tried adding the tag below in the manifest but this does not work.
<DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"/>
The part that you added in the manifest file enabled Fast App Resume, which means that your application won't be relaunched as a new instance if it is sitting in the background. But this doesn't guarantee that your input boxes will get their data restored. For this, you need to preserve the page state and restore it when the app resumes. Read more about this here.

Linking to the app's Store Page on WP7 using XNA

Is it possible for an XNA game/app to obtain it's own store link url through code or would I have to submit an app, wait for it's store link to become available and release an update including the store link?
Basically I want the player to be able to post his or her score to any social networks set up along with a link to the store page.
-Short question I know but my Google-Fu failed me this time.
To get a store URL, you will need to get hold of the app id. This is done by calling GetManifestAttributeValue. Note that the actual app id (Product ID) is generated when the app is published, and is different than the temporary one that is in WMAppManifest.xml. This causes a chicken and egg scenario when it comes to testing this.
See this for detailed instructions:
http://code.msdn.microsoft.com/Generating-a-Windows-Phone-9d19f939/
If all you need is to link to store from within your app, then use MarketplaceDetailTask to launch to the store. Leave ContentIdentifier as null and it will attempt to bring up the detail page of the current app. If you need to bring up the detail page of a different app, then you will need to know the app id, which you can only get after that app has been published.
http://msdn.microsoft.com/en-us/library/hh394017%28v=vs.92%29.aspx

Categories

Resources