Am working in asp.net and had to rewrite some urls rewriting is working fine here is an example I had to change URL mywebsite.com/search.aspx?cat=1 to mywebsite.com/search/cameras and it's working fine now I have to change page meta tags and when I try to get url by using
HttpContext.Current.Request.Url.PathAndQuery
am getting search.aspx?cat=1
while I want here is address written in address bar which is search/cameras
if it's not possible than is there any way to set meta tags for specific pages?
here is code for url rewrite
m_boolIsCustomPage = true;
m_strPageBaseUrl = "search.aspx";
if (m_intIDSearch > -1)
{
l_strQueryContents = m_intIDSearch.ToString();
m_intIDSearch = -1;
}
else
{
l_strQueryContents = "-1";
m_intIDSearch = -1;
}
HttpContext.Current.Request.RawUrl
As received by IIS prior to any manipulation.
Request.RawUrl vs. Request.Url
Related
I am trying to simulate navigating Netgear Managed Switch (GC108PP) local UI webpage in C#. When sending HttpWebRequest using a Chrome browser, I've learned using Fiddler - there are 3 WebForms that are generated when hitting this URL:
http://192.168.50.101
ends up being:
http://192.168.50.101/cgi/get.cgi?cmd=home_login&dummy=1582137153063&bj4=3f104a21e12a9584d36372142f16e35b
WebForms:
cmd=home_login
dummy=1582137153063 (time since epoch, this one was easy to figure out)
bj4=3f104a21e12a9584d36372142f16e35b (trying to figure out how to generate this one)
There is no HTTP API to reference from Netgear. I have tried just generating a 32 char string with:
private static Random random = new Random();
public static string randomString(int length)
{
const string chars = "abcdef0123456789";
return new string(Enumerable.Repeat(chars, length).Select(s =>s[random.Next(s.Length)]).ToArray());
}
However, I get ERROR 400 Bad Request.If I use a bj4 key/ID that gets generated by my browser statically in my code it works, but I want to be generating this webform properly.
Any ideas on how this WebForm might be be generated?
Found it in the JS...
function gotoLogin()
{
document.cookie = \"testcookie\";
cookieEnabled = (document.cookie.indexOf(\"testcookie\") != -1) ? true : false;
if (cookieEnabled == false)
{
alert(\"Browser does not accept cookies. Please configure your browser to accept cookies in order to access the Web Interface.\");
}
var fileVer = (new Date().getTime());
var url = \"login.html?aj4=\"+fileVer;
url = url + '&bj4=' + md5(url.split('?')[1]); //here!!!
window.location.href=url;
}
I am trying to create a Virtual user with and redirect to content editor as below.
string userId = string.Format("{0}\\{1}", "sitecore", "testadmin");
var scUser = AuthenticationManager.BuildVirtualUser(userId, true);
scUser.RuntimeSettings.IsAdministrator = true;
scUser.RuntimeSettings.AddedRoles.Add(#"sitecore\Sitecore Client Authoring");
AuthenticationManager.Login(scUser);
string url = "/sitecore/shell/sitecore/content/Applications/Content Editor.aspx?id=%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d&la=en&fo=%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d";
url = string.IsNullOrEmpty(url) ? "/" : url;
HttpContext.Current.Response.Redirect(url, false);
But it always redirects the user to sitecore/login page.
Any idea what is the issue here?
Interesting. I'm not entirely sure that approach is a supported scenario. However, the Content Editor runs off the "shell" website, possibly that is your issue.
Try putting this code around your entire code block.
using(new SiteContextSwitcher("shell")) {
}
You need to change:
AuthenticationManager.Login(scUser);
to
AuthenticationManager.LoginVirtualUser(scUser);
I have a ASP.NET MVC application which will work on a IIS7.
I don't know the final URL yet, and that's the problem.
I want to get the URL-Parts between the Top-level-domain and my controller.
For examople: http://www.mydomain.com/myApplication/MyController/ControllerMethodshould return /myApplication/MyController/
This should also be possible, if the application is called via the standard method, for example http://www.mydomain.com/myApplication.
The Problem is that with my method it works perfectly if the full controller- and methodname is in the url, but as soon as there is only the controller name and the route takes the default index-method or there is no controller/method and the route takes the default controller/method, it will fail because my code puts wrong output.
I thought about hardcoding the controller-name and make a if-then-else orgy, but this doesn't seem very professional...
Maybe anyone of you has got an Idea.
Here's my function:
String segments = Request.Url.Segments;
System.Text.StringBuilder builder = new System.Text.StringBuilder();
String lastSegment = "";
int i= 0;
do
{
builder.Append(segments[i]);
lastSegment = segments[i++];
} while(!lastSegment.Equals("Home") && !lastSegment.Equals("Home/") && i < segments.Length);
return builder.toString();
Use the Url class to build the Urls for you http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper(v=vs.118).aspx
i writen this code
im using it for checking if a certin url is found on a web page
private void checkUrls (){
WebClient client;
for (int i = 0; i < Convert.ToInt32(txtnum.Text); i++) {
try
{
string Url = "http://www." + txtUrl.Text + i.ToString();
client = new WebClient();
string result = client.DownloadString(Url);
if (result.Contains(txtsearch.Text))
MessageBox.Show(Url);
}
catch (Exception ex) { }
the base url look like this:
http://www.example.com/?p=35
but on two sites when i ask for this:
http://www.example.com/?p=35
i get redirected to somthing like this
http://www.example.com/some_categoery/postitle/
i need to search the site in the first manner
but to download the content of the freindly url
can anyone show me the right direction to do so ?
i checking website where i do no know how many pages there on the site
You could try the HtmlAgilityPack to get all the anchor tags and check the href attribute for the value you want.
How to screen scrape HTTPS using C#?
You can use System.Net.WebClient to start an HTTPS connection, and pull down the page to scrape with that.
Look into the Html Agility Pack.
You can use System.Net.WebClient to grab web pages. Here is an example: http://www.codersource.net/csharp_screen_scraping.html
If for some reason you're having trouble with accessing the page as a web-client or you want to make it seem like the request is from a browser, you could use the web-browser control in an app, load the page in it and use the source of the loaded content from the web-browser control.
Here's a concrete (albeit trivial) example. You can pass a ship name to VesselFinder in the querystring, but even if it only finds one ship with that name it still shows you the search results screen with one ship. This example detects that case and takes the user straight to the tracking map for the ship.
string strName = "SAFMARINE MAFADI";
string strURL = "https://www.vesselfinder.com/vessels?name=" + HttpUtility.UrlEncode(strName);
string strReturnURL = strURL;
string strToSearch = "/?imo=";
string strPage = string.Empty;
byte[] aReqtHTML;
WebClient objWebClient = new WebClient();
objWebClient.Headers.Add("User-Agent: Other"); //You must do this or HTTPS won't work
aReqtHTML = objWebClient.DownloadData(strURL); //Do the name search
UTF8Encoding utf8 = new UTF8Encoding();
strPage = utf8.GetString(aReqtHTML); // get the string from the bytes
if (strPage.IndexOf(strToSearch) != strPage.LastIndexOf(strToSearch))
{
//more than one instance found, so leave return URL as name search
}
else if (strPage.Contains(strToSearch) == true)
{
//find the ship's IMO
strPage = strPage.Substring(strPage.IndexOf(strToSearch)); //cut off the stuff before
strPage = strPage.Substring(0, strPage.IndexOf("\"")); //cut off the stuff after
}
strReturnURL = "https://www.vesselfinder.com" + strPage;