Click here to Skip to main content
14,976,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have made a website in which i have used URL Re Writing.

through which i changed my original url http://www.mywebsite.com/tender.aspx to http://www.mywebsite.com/onlinetenders


i have implemented it in Global.asax file in Application_BeginRequest function.

it is working fine when i upload website at root domain of my website which is http://www.mywebsite.com but when i create virtual folder named en for enlish version. so that i can run multiple versions in single domain setup then it is creating problem. and script url and css link url is rendering correct path. modfied path should start from http://www.mywebsite.com/en/ for all links as i have created web application under new virtual folder. but it is still taking path from root website http://www.mywebsite.com. after that, content of that page is not showing properly.

I want to know how to make content page relative to physical path of page not with re write path.

I may have choosen the way of routing or another rewrite module. but i have to make rewriting work in Global.asax in Application_BeginRequest function because i am making url dynamic for CMS application.


Improtant :- Please do not be confused with en as culture, i am taking it as sub domain so that string can be changed. and new sub domain path can be anything like http://www.mywebsite.com/onlineapp.


HttpContext InRequest = HttpContext.Current;

string path = InRequest.Request.Path;

C#
if (path.ToUpper().Contains("/onlinetenders") == true)
        {
            path = "frmTenderDetails.aspx";
            if (InRequest.Request.QueryString.Count != 0)
            {
                string sign = (path.IndexOf('?') == -1) ? "?" : "&";
                path = path + sign + InRequest.Request.QueryString.ToString();
            }
            else
            {
                path = path + "?cd=" + InRequest.Server.UrlEncode(db.EncodeTo64("0"));
            }

            string rew = "~/" + path;

            InRequest.Items.Add(
                "OriginalUrl",
                HttpContext.Current.Request.RawUrl);

            string baseUrl = "~/frmTenderDetails.aspx?";

            string qrstr = rew.Substring(baseUrl.Length, rew.Length - baseUrl.Length);

            InRequest.RewritePath(baseUrl.Substring(0, baseUrl.Length - 1), "", qrstr, true);

            //InRequest.RewritePath("~/frmTenderDetails.aspx", "", "", true);
        }
Posted
Updated 5-Jul-15 18:59pm
v6
Comments
Kornfeld Eliyahu Peter 22-Jun-15 5:33am
   
Please show the part of the URL rewriting of your code...
Gaurav Gupta A Tech Guy 26-Jun-15 1:46am
   
Please help me ?
CHill60 22-Jun-15 8:25am
   
When you post the URL rewriting of your code use the Improve question link and also change the all-capitals in you title to mixed-case. All capitals is considered shouting and rude, so fewer people will be inclined to read your question and help
Gaurav Gupta A Tech Guy 26-Jun-15 1:43am
   
Please help me ?
CHill60 27-Jun-15 6:47am
   
This is not my area of expertise - I was only helping you to change your question to make sure more people would look at it.
I suggest trying to think of anything else you can add to the information and edit your question again - it will move back to the front of the list which might help an expert spot it. Don't do that too often though or it will annoy members
Gaurav Gupta A Tech Guy 28-Jun-15 0:57am
   
Thank you for suggestion...
Gaurav Gupta A Tech Guy 22-Jun-15 9:33am
   
Please help me out now?
Richard MacCutchan 22-Jun-15 9:40am
   
Please don't do that. People here answer questions in their own time, and at no cost to you, so learn to be patient.
Gaurav Gupta A Tech Guy 23-Jun-15 1:03am
   
ok..
Sreekanth Mothukuru 29-Jun-15 2:50am
   
why don't you create a new route which support culture and localization and not by creating a virtual path.

Here is an example on how to create a route with culture:

routes.MapRoute(
name: "DefaultWithCulture",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = "en-US", controller = "Home", action = "Index", area = "", id = UrlParameter.Optional }
);
Gaurav Gupta A Tech Guy 4-Jul-15 6:40am
   
Problem with is that rewriting is working for dynamic items of asp.net but not for images, js, css files etc. when rewriting is done, it is taking url of content from root domain (http://www.mywebsite.com/mycss.css), it is not including sub domain path (http://www.mywebsite.com/en/mycss.css ).
Sreekanth Mothukuru 4-Jul-15 9:25am
   
In general scenario, we do not apply localization to either images, css or js files. To get appropriate images based on your culture selection, you need to rely on resource files.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

The statement above will avoid routing mechanism for all resources like css or js files.
Gaurav Gupta A Tech Guy 6-Jul-15 0:51am
   
Please see my question again. i have improved my question for better understanding. you will see that the problem is something else.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900