13

If I use the following line in my default view /Home/Index

<script language="javascript" src="<%=Url.Content("~/Scripts/jquery-1.3.2.js")%>" type="text/javascript" ></script>

If I surf to this location using the following url http://127.0.0.1:9999/Home/Index the page gets rendered correctly

<script language="javascript" src="/Scripts/jquery-1.3.2.js" type="text/javascript" ></script>

If I use the following url http://127.0.0.1:9999/ (default wired to Home/Index) the page renders this:

<script language="javascript" src="//Scripts/jquery-1.3.2.js" type="text/javascript" ></script>

Does anyone has any idea how to solve this issue?

EDIT:

FYI: I'm using ASP.NET mvc 2 RC And this is my route configuration:

routes.MapRoute(
 "Default",                                              // Route name
 "{controller}/{action}/{id}",                           // URL with parameters
 new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);
2
  • 1
    sorry but i can`t reproduce this behavior. could you please post the content of your RegisterRoutes() procedure and what version of asp.net mvc you are using? Commented Jan 22, 2010 at 13:32
  • As Marc says, this shouldn't be happening. I can't reproduce it either. Commented Feb 18, 2010 at 21:44

4 Answers 4

1

If you use IIS6 or WinXP Cassini you should register one more route:

if (Environment.OSVersion.Version.Major < 6) // IIS6 and WinXP Cassini
        {
            routes.MapRoute(
                "Root",
                "",
                new
                    {
                        controller = "Home",
                        action = "Index",
                        id = UrlParameter.Optional
                    }
                );
        }
Sign up to request clarification or add additional context in comments.

Comments

0

I had a very similar problem with Asp.net using Request.ApplicationPath... and wrapped it as follows

    public string AppRoot()
    {
        var appPath = Request.ApplicationPath;
        if (appPath.EndsWith("/"))
            return appPath;
        else
            return appPath + "/";

    }

Comments

0

Well, alternatively you can do the following:

create a key in appSettings section of web.config file.

<add key="DomainName" value="http://http://127.0.0.1:9999/" />

Now, whenever you want to assign "src" value of any image, javascript of css file, you can use this key. it will be define a root for you and after that you can define at what path you have placed your file. i.e. in your case:

<script language="javascript" src="<%=System.Configuration.ConfigurationManager.AppSettings["DomainName"] %>Scripts/jquery-1.3.2.js" type="text/javascript" ></script>

Comments

0

Why are you keeping your id as an empty string? I think this may be causing the problem. You may find better results by trying the following:

routes.MapRoute(
 "Default",                                              // Route name
 "{controller}/{action}/{id}",                           // URL with parameters
 new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

to this

routes.MapRoute(
 "Default",                                              // Route name
 "{controller}/{action}/{id}",                           // URL with parameters
 new { controller = "Home", action = "Index", UrlParameter.Optional }  // Parameter defaults
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.