Inserting Google Maps into my Web Page in asp.net - c#

I am creating a web app. where I want be able to incorporate Google Maps into 1 of my pages.
From what I have read in other places, the easiest think is to place a web browser onto the form but there is no 'Web Browser' in the tool-box.
What I am trying to do is to insert a location into a textbox(ie. London) and insert a type of sport(ieCycling) and the resultant map shows up. Is there any other way in doing this in C# other than using the web browser tool.
Here is my code:
protected void btnSearch_Click(object sender, EventArgs e)
{
string sport = txtSport.Text;
string location = txtLocation.Text;
try
{
StringBuilder queryAddrress = new StringBuilder();
queryAddrress.Append("https://maps.google.ie/");
if (sport != string.Empty)
{
queryAddrress.Append(sport+","+"+");
}
if (location != string.Empty)
{
queryAddrress.Append(location + "," + "+");
}
Panel1.Navigate(queryAddrress.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(),"Error");
}
} protected void btnSearch_Click(object sender, EventArgs e)
{
string sport = txtSport.Text;
string location = txtLocation.Text;
try
{
StringBuilder queryAddrress = new StringBuilder();
queryAddrress.Append("https://maps.google.ie/");
if (sport != string.Empty)
{
queryAddrress.Append(sport+","+"+");
}
if (location != string.Empty)
{
queryAddrress.Append(location + "," + "+");
}
Panel1.Navigate(queryAddrress.ToString());
}
I tried to put the address into a panel but this is clearly wrong. Any help would be greatly appreciated!

It seems like you are very confused and mixing ASP.NET Web Forms with Windows Forms.
Specifically, MessageBox.Show() would open a Windows message box, not a browser window. And it would happen on the server side for whatever user your web server runs as. Probably not the desired intention. Also, you can't "put a web browser" onto a page. There is a WebBrowser control for Windows Forms, which embeds a minified version of Internet Explorer into a Windows application. But again, probably not what you want.
ASP.NET can be used as if it were just a normal HTML site. So find some Google Maps tutorials for HTML and follow those.

Related

How to Stop IIS Website on muliple Servers using checkedlistbox

I have a winform that can stop and start IIS website remotely however I'm looking for a way to stop/start website on muliple servers by using checkedlistbox. Here's my Stop IIS website code
private void buttonStop_Click(object sender, EventArgs e)
{
string serverName = textServer.Text;
string siteName = cmbWebsite.SelectedItem.ToString();
using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName))
{
Microsoft.Web.Administration.Site site = sm.Sites.Where(q => q.Name.Equals(siteName)).FirstOrDefault();
// If the site does not exist, throw an exception
if (site == null)
{
throw new Exception("The specified site was not found!");
}
// Stop the site
site.Stop();
showStatus(siteName);
}
}
I wanted to be able to run this on multiple servers so instead of putting the server (textServer) on the text box. User can just check on which server/server they wanted to stop.
Any assistance is greatly apprecieated.
Thanks!
using (Microsoft.Web.Administration.ServerManager sm = Microsoft.Web.Administration.ServerManager.OpenRemote(serverName))
{
foreach(var server in checkedListBox1.CheckedItems)
{
try
{
Microsoft.Web.Administration.Site site = sm.Sites.Where(q => q.Name.Equals(server.ToString())).FirstOrDefault();
site.Stop();
showStatus(siteName);
}
catch(Exception e) { /*handle*/ }
}
}
you just want to loop through the items

Transfer ASP.NET session to other ASP.NET solution

I got a 2 ASP.NET solution. The first one is called HomePage and the other Main. I'm using IIS 7.5. At the root of IIS, I got 2 folders with the same name (HomePage and Main). Each solution is in their own folder.
I'm trying to transfer a session from HomePage to Main.
Main project (file ASPNETToASPNET.aspx)
private void Page_Load(object sender, System.EventArgs e)
{
string queryString = String.Empty;
string destPage = Request.Form["destpage"].ToString();
...
}
HomePage.aspx
private void Redirect_Click(object sender, CommandEventArgs e)
{
Response.Redirect("http://www.website.com/Main/Pages/ASPNETToASPNET.aspx?destpage=" + e.CommandArgument + "&SessionNoClient=" + Session["SessionNoClient"], false);
Response.Redirect("./Main/Pages/ASPNETToASPNET.aspx?destpage=" + e.CommandArgument + "&SessionNoClient=" + Session["SessionNoClient"], false);
}
When using the first redirect, I reach the appropriate file, but I got an error at line
string destPage = Request.Form["destpage"].ToString();
Object reference not set to an instance of an object.
When using the other redirect, I'm not able to find a way to reach the appropriate file.
As mentioned, both solutions are on same server and use the same domain.
Any solutions?
string destPage = Request.QueryString["destpage"];
This is not a transfer of session, you're just passing query parameters.
Request.Form collection contains POST values. For query string parameters (GET) use Request.QueryString or Request.Params, the last one searches your value in QueryString, Form, Cookies, and ServerVariables.

How to intercept when user click on a link in a webbrowser

I'm trying to intercept tapping on a link in a WebBrowser control.
My HTML page contains custom links, for some starting with shared:// I'd like to intercept when the user tap on it.
On iPhone I would use the webView:shouldStartLoadWithRequest:navigationType: method, and look at the URL that is selected.
I haven't managed to reproduce a similar behaviour with Silverlight for Windows Phone.
I do something like:
{
webBrowser1.Navigating += new EventHandler<NavigatingEventArgs>(webBrowser1_Navigating);
}
void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
string scheme = null;
try
{
scheme = e.Uri.Scheme; // <- this is throwing an exception here
}
catch
{
}
if (scheme == null || scheme == "file")
return;
// Not going to follow any other link
e.Cancel = true;
if (scheme == "shared")
{
}
But I guess an exception when reading some properties of the Uri, when it's a standard Uri with a default file:// URL
Additionally, the Navigating event isn't even triggered for links starting with shared://
Now that I'm able to capture tapping on a shared:// I do not care much, but at least I'd like to be able to retrieve the URL we're going to navigate to, and cancel the default operation for a particular URL.
Any ideas what's going on?
Thanks
Edit:
It turned out that the problem is that the Navigating event is only generated for the following links: file://, http:// or mailto://
The scheme attributes of the Uri is only available for the http:// and mailto:// links
so what I did in the end is replace the shared:// link with http://shared/blah ... And I look at the URL... This works for my purpose. I can now have links that have a different action (like opening an extra window) depending on the links in the html.
Here is my final code, in case this is useful for someone in the future:
For an about screen, I use an html file displayed in a WebBrowser component.
The about page has a "tell your friend about this app" link as well as links to external web site.
It also has local subpages.
Local sub-pages are linked to using a file:// link. Those can be navigated within the WebBrowser component.
External links are opened externally with Internet Explorer.
Tell your friend link is made of a http://shared link, that opens an email with a pre-set subject and body. Unfortunately, no other scheme than the standard ones are usable as they do not trigger a Navigating event
There's also a support link which is a mailto:// link and opens an EmailComposeTask
void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
{
String scheme = null;
try
{
scheme = e.Uri.Scheme;
}
catch
{
}
if (scheme == null || scheme == "file")
return;
// Not going to follow any other link
e.Cancel = true;
if (scheme == "http")
{
// Check if it's the "shared" URL
if (e.Uri.Host == "shared")
{
// Start email
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.Subject = "Sharing an app with you";
emailComposeTask.Body = "You may like this app...";
emailComposeTask.Show();
}
else
{
// start it in Internet Explorer
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(e.Uri.AbsoluteUri);
webBrowserTask.Show();
}
}
if (scheme == "mailto")
{
EmailComposeTask emailComposeTask = new EmailComposeTask();
emailComposeTask.To = e.Uri.AbsoluteUri;
emailComposeTask.Show();
}
}

asp.net (C#) Facebook GetInfo()

I am struggling to get off with ground with some Facebook dev work. All I want to do is retireve some user info for the logged in user. This is the code I got from another site & it looks fine to me, however is always returns IsConnected() to be false.
I am running this code within an iframe on my facebook app (in sandbox mode)
private const string APPLICATION_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxx";
private const string SECRET_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
public Facebook.Rest.Api Api;
private Facebook.Session.ConnectSession _connectSession;
protected void Page_Load(object sender, EventArgs e)
{
_connectSession = new Facebook.Session.ConnectSession(APPLICATION_KEY,SECRET_KEY);
if (!_connectSession.IsConnected())
{
lit.Text = "Please sign-in with Facebook.";
}
else
{
try
{
Api = new Facebook.Rest.Api(_connectSession);
Facebook.Schema.user u = Api.Users.GetInfo();
img.ImageUrl = u.pic_square;
lit.Text = string.Format("Welcome, " + u.name);
}
catch (Exception ex)
{
lit.Text = ex.Message;
}
}
}
See this other SO question about a similar problem. The poster apparently found what he was looking for, but didn't know how to implement it. You may be able to do so, since there's a lot of information in the question body.

Meet with error -- "Updates are currently disallowed on GET requests"

I am using SharePoint Server 2007 Enterprise with Windows Server 2008 Enterprise. I have deployed a publishing portal. I am developing a ASP.Net web application using VSTS 2008 + C# + .Net 3.5 + ASP.Net + SharePoint Server 2007 SDK.
Here is my code snippets and I got error -- "Updates are currently disallowed on GET requests". Any ideas how to fix?
Microsoft.SharePoint.SPException: Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.
protected void Page_Load(object sender, EventArgs e)
{
try
{
SPWebApplication webApp = SPContext.Current.Site.WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
foreach (SPSite item in siteCollections)
{
SPWeb webItem = item.OpenWeb();
webItem.AllowUnsafeUpdates = true;
}
SPSite newSiteCollection = siteCollections.Add("sites/myblog",
"New Sample Site", "New Sample Site Description", 1033, "BLOG#0",
"foo\\foouser", "Owner name", "owneremail#foo.com");
}
catch (Exception ex)
{
Response.Write(ex.ToString() + "\t" + ex.StackTrace);
}
}
The problem why you are not allowed to read/write to database on GET request is because your code will be exploitable via a cross-site scripting. Read about AllowUnsafeUpdates consequences here.
Anyway, if you like, you can set this SPWeb.AllowUnsafeUpdates to true, but use it like this:
try {
web.AllowUnsafeUpdates = true;
...
}
finally {
web.AllowUnsafeUpdates = false;
}
Add a check to ensure that you are getting a POST instead of a GET before you attempt to allow updates. Make sure that whatever is making the change does it via a POST request rather than using URL parameters and a GET.
if (IsPostBack)
{
...
}

Categories

Resources