Invalid script request

I launch Nancy using Self Hosting / OWIN and the Razor view engine

In particular:

Nancy 0.21.1
Nancy.ViewEngines.Razor 0.21.1
Microsoft Owin.SelfHost 2.0.1

I have an html page with the following script link

<script src="Scripts/jquery-1.6.4.min.js"></script>

If I make the following request (mark the trailing slash)

http://localhost:3456/log/

The html page returns correctly and the following script request is executed

http://localhost:3456/log/Scripts/jquery-1.6.4.min.js

This is the correct behavior.

If I make this request (note that there is no slash)

http://localhost:3456/log

The html page returned, however another script request is executed.

http://localhost:3456/Scripts/jquery-1.6.4.min.js

This fails because it is the wrong URL. script must be under / log

Nancy allows you to change the URL before it is processed, so I tried adding a trailing slash if it is missing, but that doesn't change anything (it seems to crack)

, , . , , , HTTP- ? , .

N.B. . , , . , , .

, , , ASP.NET

http://forums.asp.net/t/1897093.aspx?Trailing+Slash+Nightmare

1

@AndreD,

/log/Scripts/jquery-1.6.4.min.js

, "" . html , , , .

+4
1

, , script

/log/Scripts/jquery-1.6.4.min.js

*SomeNamespace*

public static class UrlHelpers
{
  public static string Script<TModel>(this Nancy.ViewEngines.Razor.UrlHelpers<TModel> Self,     string Script)
  {
    var rootPath = Self.RenderContext.Context.Request.Path.TrimEnd('/');
    var scriptPath = string.Format("{0}/Scripts/{1}", rootPath, Script);
    return scriptPath;
   }
}

:

@using SomeNamespace
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase
  ...
  ...

  <script src=@Url.Script("jquery-1.6.4.min.js")></script>
  <script src=@Url.Script("jquery.signalR-2.0.0.min.js")></script>
+1

All Articles