how can I get url of page ASPNET C#

D

Dariusz Tomon

Hi

How can I get url of page so taht I can pass it to string varaible.

I have got several urls in my IIS under one folder. I want to have one
default.aspx where code under it recognize which url is used by user and
then display appropriate data to that url (one url is about fashion, other
about law and so on). By means of recognition of url I can display
appropriate banners for example.

Regards

Darek T
 
K

Karl Seguin [MVP]

Have you looked at the Request.Url property? it has a lot of useful
properties such as Request.Url.AbolustePath and Request.Url.Segments

Karl
 
D

DKode

I dont really understand your question here.

Is each URL a different aspx page or do you use a query string to
access the different pages?

If each URL is a seperate aspx page, then you can use Request.Url to
get information about the requested URL.

If you use query strings, IE: (default.aspx?page=fashion) then you can
use Request.QueryString to get the query string requested.
 
G

George Ter-Saakov

It's totaly unclear what you want
Here is couple thing for you to look at ( I think one will help).

1.Application_BeginRequest in Global.asax to get URL before any ASPX page
gets it.
2. HttpContext.RewritePath to modify URL before ASPX page gets it.
3. Request.ServerVariables("HTTP_URL") to get requested URL


George.
 
D

Dariusz Tomon

telling the truth it is complicated I cannot tell you how server recognize
what content to run:

1) Default.aspx is the same for two areas (fashion and furniture).

Default.aspx:

<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="EuroDomWnetrze._Default" %>
<%@ Register TagPrefix="euroc" TagName="HeaderControl"
Src="WebControl/HeaderControl.ascx" %>
<%@ Register TagPrefix="euroc" TagName="FooterContol"
Src="WebControl/FooterContol.ascx" %>
<%@ Register TagPrefix="euroc" TagName="MenuiControl"
Src="WebControl/MenuiControl.ascx" %>
<%@ Register TagPrefix="euroc" TagName="BoxyControl"
Src="WebControl/BoxyControl.ascx" %>
<%@ Register TagPrefix="euroc" TagName="LicznikControl"
Src="WebControl/LicznikControl.ascx" %>
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl">
<head>
<title>EuroAdres » Dom &amp; Wnetrze</title>
<meta name="author" content="Mariusz Turczyniak Tomasz Sribniak" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="generator" content="WebSite PRO 4.3"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="CODE_LANGUAGE" content="C#"/>
<meta name="vs_defaultClientScript" content="JavaScript"/>
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5"/>
<link href="http://www.euroadres.pl/App.ico" rel="shortcut icon"
type="image/x-icon"/>
<link type="text/css" href="Css/Default.css" rel="stylesheet"
title="Podstawowy wyglad"/>
</head>
<body>
<div id="Strona">
<euroc:LicznikControl id="LicznikControl1"
runat="server"></euroc:LicznikControl>
<euroc:HeaderControl id="HeaderControl1"
runat="server"></euroc:HeaderControl>
<div id="DivLewyBG">
<euroc:MenuiControl id="MenuiControl1"
runat="server"></euroc:MenuiControl>
<euroc:BoxyControl id="BoxyControl1" runat="server"></euroc:BoxyControl>
</div>
<euroc:FooterContol id="FooterContol1"
runat="server"></euroc:FooterContol>
</div>
</body>
</html>

<<<<<END>>>>>

(There is nothing interesting in Default.aspx.cs

THEN

You can see line: <euroc:HeaderControl id="HeaderControl1"
runat="server"></euroc:HeaderControl>
So Default.aspx is using webcontrol called HeaderControl.ascx (code
below):

<<<START>>>

<%@ Register TagPrefix="basic" Namespace="EuroAdresBasic"
Assembly="EuroAdresBasic" %>
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="HeaderControl.ascx.cs"
Inherits="EuroDomWnetrze.WebControl.HeaderControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<div id="DivEuroAdresBaner" runat="server">
<!-- EuroAdresBaner --></div>
<div id="DivBalkaHeader" runat="server"></div>
<div id="DivBaner" runat="server">
<!-- Baner --></div>
<div id="DivSerwis_" runat="server"><basic:eserwisycontrol
id="ESerwisyControl1" runat="server"></basic:eserwisycontrol></div>

<<<END>>>

<<<CODE>>> - the class under webcontrol HeaderControl - called
HeaderControl.ascx.cs

<<<START>>>

namespace EuroDomWnetrze.WebControl
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EuroAdresBasic;
/// <summary>
/// Summary description for HeaderControl.
/// </summary>
public class HeaderControl : System.Web.UI.UserControl
{
/// <summary>

/// Set url before setting banner
/// </summary>
public string UrlBaner
{
set {url = value;}
}

public string Naglowek
{
set
{
naglowek = value;

if (value.Length > 0)
doBaner();
else
doDefaultBaner();
}
}

public int IdJezyk
{
set
{
idJezyk = value;
if (idJezyk != 1)
DivSerwis_.Controls.Clear();
}
}

private int idJezyk = 1;
private string naglowek = "";
private string url;

protected HtmlGenericControl DivEuroAdresBaner;
protected HtmlGenericControl DivBaner;
protected HtmlGenericControl DivSerwis_;
protected EuroAdresBasic.ESerwisyControl ESerwisyControl1;
protected EuroAdresBasic.EFlashControl EuroBaner;
protected HtmlGenericControl DivBalkaHeader;

protected HtmlGenericControl image;


private void Page_Load(object sender, System.EventArgs e)
{
test.Service1 s = new test.Service1();
if (!s.AAAA())
Response.StatusCode = 404;

Response.StatusCode = 404;
EuroBaner = new EFlashControl("Img/All/naglowek.swf", "770", "119",
"flashvars", getFlaszParam());
DivEuroAdresBaner.Controls.Add(EuroBaner);

if (Page.

//DivBalkaHeader.Controls.Add(new EFlashControl("waluty_swf.swf", "770",
"19","flashvars", "uerel=http://www.euroadres.pl/Waluty.aspx"));

doDefaultBaner ();
}

private void doDefaultBaner ()
{
DivBaner.Controls.Add(new EFlashControl("Img/All/billboard_DW.swf",
"770","200"));
}
private void doBaner ()
{
// DivBaner.Controls.Clear();
//
// if (!naglowek.EndsWith(".swf"))
// {
// HtmlImage img = new HtmlImage();
// img.Style.Add("width","770px");
// img.Style.Add("height","200px");
// img.Src = "../images/loga/"+naglowek+"\"";
// img.Alt = "baner";
//
// if (url != "")
// {
// HtmlAnchor link = new HtmlAnchor();
// link.HRef = "http://" + url;
// link.Target = "_blank";
// link.Controls.Add(img);
// DivBaner.Controls.Add(link);
// }
// else
// DivBaner.Controls.Add(img);
// }
// else
// {
// if (url != "")
// {
// DivBaner.Controls.Add(new EFlashControl("images/loga/" + naglowek,
"770","200", "flashvars", "uerel=http://"+url+"&okno=1"));
// }
// else
// DivBaner.Controls.Add(new EFlashControl("images/loga/" + naglowek,
"770","200"));
// }
}
private string getFlaszParam ()
{
string flashParem = "data=";
flashParem += DateTime.Now.ToLongDateString() + "&";
flashParem += "linki=Polski*http://www.euroadres.pl/zmienjezyk.aspx*1|";
flashParem += "English*http://www.euroadres.pl/zmienjezyk.aspx*2|";
flashParem += "Francais*http://www.euroadres.pl/zmienjezyk.aspx*3|";
flashParem += "Magyar*http://www.euroadres.pl/zmienjezyk.aspx*4|";
flashParem += "???????*http://www.euroadres.pl/zmienjezyk.aspx*14|";
flashParem += "&strona_startowa=default.aspx";
flashParem += "&haslo="+ getTwojAdres();

return flashParem;
}

private string getTwojAdres()
{
// using (System.IO.TextReader tr =
// new
System.IO.StreamReader(Server.MapPath(@"Xml\Tlumaczenia.xml"),System.Text.Encoding.UTF8))
// {
// System.Xml.XmlReader x = new System.Xml.XmlTextReader(tr);
//
// while(x.Read())
// if (x.IsStartElement("tlumaczenia"))
// while(x.Read())
// {
// if (x.IsStartElement("tlumaczenie"))
// {
// string at = x.GetAttribute("co");
// if (at == "Twój europejski adres")
// {
// while(x.Read())
// {
// if (x.IsStartElement("fraza"))
// {
// int jez = int.Parse( x.GetAttribute("idjezyk"));
// if (jez == idJezyk)
// {
// return x.ReadString();
// }
// }
// }
// }
// }
// }
//
// x.Close();
// }
return "Twój europejski adres";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

<<<END>>>

I wonder how this code could recognize or guess :) - what to display?

The fact is that when you enter: http://www.domiwnetrze.com/ and
http://www.modaistyl.com.pl/ you'll get the other content still based on the
same default.aspx and even the same HeaderControl.ascx

How to explain it?

Best Regards

Dariusz Tomon
 
G

George Ter-Saakov

This is called HOST you can get host information by
Request.Url.Host or Request.ServerVarables("HTTP_HOST")


George.




......skipped.....
 
D

Dariusz Tomon

thank you - I'll do that and let you know.

D.T.

George Ter-Saakov said:
It's totaly unclear what you want
Here is couple thing for you to look at ( I think one will help).

1.Application_BeginRequest in Global.asax to get URL before any ASPX page
gets it.
2. HttpContext.RewritePath to modify URL before ASPX page gets it.
3. Request.ServerVariables("HTTP_URL") to get requested URL


George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top