Get a root domain on asp.net - asp.net

how can I get only the domain, for example:
The url: http://localhost:11093/SiteA/Admin/Default.aspx
Then, I want to get only the: http://localhost:11093/SiteA/
I am using:
Path.GetFileName(Request.Url.Host)
But only get the: localhost, and trying:
Path.GetFileName(Request.Url.PathAndQuery)
But get the whole address. Thank you very much.

Try this one:
var HostAndPath = Request.Url.AbsoluteUri.Replace(Request.Uri.AbsolutePath, "")

Try something like this
Uri uri = new Uri("http://localhost:11093/SiteA/Admin/Default.aspx");
string requested = uri.Scheme + uri.SchemeDelimiter + uri.Host + ":" + uri.Port;
You can work directly on the request URI
Uri uri = Request.Url;
string requested = uri.Scheme + uri.SchemeDelimiter + uri.Host + ":" + uri.Port;

Try this...
Page.ResolveUrl("~").ToString()

Related

Extract depthmap from Google Street View

Many posts such as this one use the REST API of Google Street View like this:
http://maps.google.com/cbk?output=xml&ll=40.7625000,-73.9741670&dm=1
However, this API does not work sometimes.
Google Street View seems does not rely on that REST API, and it may store the depthmap in this meta-file:
https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=us&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2sus!3m3!1m2!1e2!2sG2__WfQLZTzrsr7FP1wUyQ!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3
But I do not know how to extract depthmap from it. The method using Base64 in this post of Convert depth map (base64) of google street view to image does not work because the encoded string are very different.
Could anyone can get me some ideas? Thanks very much!
Here are some Python code lines to get the meta-file from Google Street View:
def getPanoJS_frm_lonlat(lon, lat):
url = "https://maps.googleapis.com/maps/api/js/GeoPhotoService.SingleImageSearch?pb=!1m5!1sapiv3!5sUS!11m2!1m1!1b0!2m4!1m2!3d{0:}!4d{1:}!2d50!3m10!2m2!1sen!2sGB!9m1!1e2!11m4!1m3!1e2!2b1!3e2!4m10!1e1!1e2!1e3!1e4!1e8!1e6!5m1!1e2!6m1!1e2&callback=_xdc_._v2mub5"
url = url.format(lat, lon)
return requests.get(url, proxies=None)
lon = -74.2249174
lat = 40.7040015
resp = getPanoJS_frm_lonlat(lon, lat)
line = resp.text.replace("/**/_xdc_._v2mub5 && _xdc_._v2mub5( ", "")[:-2]
# print(line)
jdata = json.loads(line)
print("This part may be the depthmap:")
print(jdata[1][5][0][5][3][2])
A part of the encoded depthmap in the metafile(not quite sure, and the entire string is too long to post here, please using the code above the download the meta-file):
Q0RrQUFBSUFBUWdCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUURUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJBUUVCQVFFQkFRRUJ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pTUTB0Q1RCd2dRbEhJY2tMV3RSOUNNVktiUVRGcVBNS1dIZVpCb2ZZOXdpQmFRRUowNTBIQ0Jud1pRcDV6UU1MNml0Q18wWWFjd3V6RG5FSTNFd25EZUNZc1FlODhQTUl1dThDX2tFLUt3dTF4RDhETVBzUEM0aGhCd241Z0lrSThfSG9fOTRRMFFwOExKa0ZoZUI1QzE3OTN3T3VORkVMSEQ1akJRZnM2d2c=
I recently came across this problem too and I decided to dig into it with the help of a friend.
I found the GSVPanoDepth.js library that hadn't been updated in a while but still had the fundamentals of decoding the data and parsing it. It was all pretty much the same except the url has changed and the structure of the data a bit too. I forked the repo and updated it to work with the new url and structure - https://github.com/sidequestlegend/GSVPanoDepth.js
// This url no longer works
// url = "http://maps.google.com/cbk?output=json&cb_client=maps_sv&v=4&dm=1&pm=1&ph=1&hl=en&panoid=" + panoId;
url = "https://www.google.com/maps/photometa/v1?authuser=0&hl=en&gl=uk&pb=!1m4!1smaps_sv.tactile!11m2!2m1!1b1!2m2!1sen!2suk!3m3!1m2!1e2!2s" +
panoId +
"!4m57!1e1!1e2!1e3!1e4!1e5!1e6!1e8!1e12!2m1!1e1!4m1!1i48!5m1!1e1!5m1!1e2!6m1!1e1!6m1!1e2!9m36!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b1!3e2!1m3!1e3!2b0!3e3!1m3!1e8!2b0!3e3!1m3!1e1!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e10!2b1!3e2!1m3!1e10!2b0!3e3"
fetch(url)
.then(res=>res.text())
.then(res=>JSON.parse(res.substr(4)))
.then(res=>res[1][0][5][0][5][1][2])
.then(res=>{
console.log(res);
return res;
})
.then(dm => {
var decoded, depthMap;
try {
decoded = self.decode(dm);
depthMap = self.parse(decoded);
} catch(e) {
console.error("Error loading depth map for pano " + panoId + "\n" + e.message + "\nAt " + e.filename + "(" + e.lineNumber + ")");
depthMap = self.createEmptyDepthMap();
}
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
})
.catch(e=>{
console.error("Request failed: " + url + "\n" + e);
var depthMap = self.createEmptyDepthMap();
if(self.onDepthLoad) {
self.depthMap = depthMap;
self.onDepthLoad();
}
});

Apex Callout HTTP Version not supported

I am working on deleting the file from the Amazon from sfdc.
I have written the code for it when am sending the request to Amazon It through error:-
System.HttpResponse[Status=HTTP Version not supported, StatusCode=505]
kindly help me to solve this problem
How can I overcome this error to pass correct request?
Code:
Datetime expire = system.now().addDays(1);
String dateString = expire.formatGmt('yyyy-MM-dd')+'T'+ expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';
String stringToSign = 'DELETE\n' +
'\n' +
'\n' +
dateString + '\n' +
('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+fname).replaceAll(' ', '');
stringToSign = stringToSign.replaceAll(' ', '%20');
System.debug('FINDME::stringToSign - ' + stringToSign);
Blob mac = Crypto.generateMac('HMacSHA1',Blob.valueOf(stringToSign), Blob.valueOf(+awsKeySet[0].AWS_Secret_Key__c));
stringToSign = EncodingUtil.base64Encode(mac);
//String encoded = EncodingUtil.urlEncode(stringToSign, 'UTF-8');
HttpRequest con = new HttpRequest();
con.setHeader('Authorization',+awsKeySet[0].AWS_AccessKey_Id__c+':' + stringToSign);
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
con.setHeader('Host',+awsKeySet[0].Name__c+'.s3.amazonaws.com');
//con.setHeader('Date', dateString);
con.setMethod('DELETE');
Http http = new Http();
HTTPResponse res = http.send(con);
System.debug('RES.GETBODY: ' + res.getBody() + ' RES.GETSTATUS: ' + res.getStatus() + ' CON.GETENDPT: ' + con.getEndPoint());
This kind of problem typically arises from an invalid URL in the HTTP request as can be seen in this post in Salesforce success community and this post in Salesforce StackExchange. This line here is where I would start:
con.setEndPoint('https://s3.amazonaws.com/'+awsKeySet[0].Name__c+'/'+'Temporary/'+fname);
There are references to an sobject field awsKeySet[0].Name__c and a variable fname that you resolve into your URL string.
Are you certain there are no spaces or unescaped characters in the underlying value of either of those?

I have generated the random number using below code in Selenium RC, but it is not working in Webdriver

For random number generation in Selenium RC, I have the code but it is not working properly in Webdriver. If I use the below code in webdriver, it is returning null. Please find the code below in webdriver
String Randnum = (String) ((JavascriptExecutor) driver).executeScript("var d=new Date().getFullYear()+new Date().getDate().toString()" +
"+new Date().getDay()" +
"+new Date().getHours()" +
"+new Date().getMinutes()" +
"+new Date().getSeconds()" +
"+new Date().getMilliseconds()");
Please help me out on this... Help will be appreciated.
Why can't you try the same thing using Java?
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter= new SimpleDateFormat("MM_dd_yyyy_hh_mm_ss");
String randomName = formatter.format(currentDate.getTime());
You are missing the return statement. Without, the javascript will run but not return anything.
String Randnum = (String) ((JavascriptExecutor) driver).executeScript("return new Date().getFullYear() + new Date().getDate().toString() + new Date().getDay() + new Date().getHours() + new Date().getMinutes() + new Date().getSeconds() + new Date().getMilliseconds()");
the javascript code below
function displayRandum()
{
var d = new Date().getFullYear()+new Date().getDate().toString() + new Date().getDay() + new Date().getHours()+new Date().getMinutes() + new Date().getSeconds()+new Date().getMilliseconds();
alert(d);
}
works perfectly. Can you try in your Selenium code, to keep everything in one line (no extra "+" and " characters).
Edit: (missed return statement. Saw Arran's reply and realized it).
function returnRandum()
{
var d = new Date().getFullYear()+new Date().getDate().toString() + new Date().getDay() + new Date().getHours()+new Date().getMinutes() + new Date().getSeconds()+new Date().getMilliseconds();
return d;
}

How to replace the file name(particular specific folder) using Asp.net?

i can replace the file name in particular folder , i wrote like this
FileInfo fsource = new FileInfo(Server.MapPath("~/PurchaseOrder/" + lblhideid.Text));
if (fsource.Exists)
{
string[] file = lblhideid.Text.Split('.');
string fName="Z-"+System.DateTime.Now.ToString("MM-dd-yyyy")+"-"+saveConsultantID+"."+file[1];
fsource.Name.Replace(lblhideid.Text, fName);
}
lblhideid.Text=image.jpeg , so i can replace the my own name like fName , how to replace the name pls give me any suggestion.
Thank u
Hemanth
I suspect you want that last line to be:
fsource.MoveTo(Server.MapPath("~/PuchaseOrder/" + fName));
You current code is only getting the filename as a string and manipulate that string. You want to manipulate the file itself.
EDIT:
Are you sure that ~/PurchaseOrder/ exists?
Try:
string originalPath = Server.MapPath("~/PurchaseOrder/" + lblhideid.Text);
FileInfo fsource = new FileInfo(originalPath);
if (fsource.Exists)
{
string newName = string.Format("Z-{0:MM-dd-yyyy}-{1}.{2}",
System.DateTime.Now,
saveConsultantID,
fsource.Extension);
string newPath = Path.Combine(fsource.DirectoryName, newName);
fsource.MoveTo(newPath);
}
Try this, what if they put a filename like file.tar.gz ?
string extension = Path.GetExtension("~/PurchaseOrder/" + lblhideid.Text);
string newName = "MYFILE." + extension
File.Move(
"~/PurchaseOrder/" + lblhideid.Text,
"~/PurchaseOrder/" + newName );

Facebook open graph action returns "false"

I'm trying to post an action to open graph but the only response I'm getting is "false".
According to the "Creating and Using Actions" portion of the API it appears that I'm doing this correctly.
Code sample below.
var url = facebook.root + 'objects/' + verb + '/' + noun + '.html';
var method = 'https://graph.facebook.com/me/joe_longstreet:' + verb + '?' + noun + '=' + url + '&distance=' + distance + '&tags=' + users + '&access_token=' + facebook.token;
FB.api(method, 'post', function(response){
if(response.error){
alert(response.error.message);
} else{
console.log(response);
var message = 'Posted to your timeline!';
alert(message);
}
});
Where verb = run, noun = route, and url = my objects page.
Specifically:
https://graph.facebook.com/me/joe_longstreet:run?route=http://joelongstreet.showoff.io/Facebook_app/objects/run/route.html&distance=&tags=1915805&access_token=ABCDE
Fake access token above. What am I doing wrong here?
Looks like you don't need to include the graph.facebook.com portion of the url. so it should just read /me/joe_longstreet:run?...

Resources