Bug in HttpRequest.PhysicalPath

Last post 01-13-2008 4:36 PM by abombss. 9 replies.

Sort Posts:

  • Bug in HttpRequest.PhysicalPath

    01-03-2008, 11:39 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    I just noticed today when I was playing around with path's that PhysicalPath does not return the path to the actual view file executing.  Adding the following to the Views/Home/About.aspx view produces an incorrect result.

    <h6>Physical Path: <%=Context.Request.PhysicalPath %></h6>

    Physical Path: C:\export\code\oss\rad-mvccontrib\ClientScript\trunk\src\MvcContrib.Samples.ClientScript\Home\About

    When it should be C:\export\code\oss\rad-mvccontrib\ClientScript\trunk\src\MvcContrib.Samples.ClientScript\Views\Home\About.aspx

     

    Adam Tybor -- abombss.com
    Filed under: ,
  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 1:48 AM
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 2:08 PM
    • Posts 805
    • ASPInsiders

    Interesting.

    I suspect its just doing MapPath("~/Home/About")

    I used this in a previous asp.net project to automatically insert script and css files if they were named Request.PhysicalPath + ".css" (or ".js") using ScriptManager and a <head> tag with runat="server". But in mvc this doesn't make much sense. I'm putting scripts and stylesheets inside the Content folder and including them explicitly... Not ideal.


  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 2:20 AM
    • Loading...
    • erdsah88
    • Joined on 12-12-2004, 11:18 AM
    • ISTANBUL
    • Posts 887

    .aspx          could be the default  extension maybe .....

     it would be funny if they missed something like this :)

    Satılık,Kiralık emlak ilanlari
  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 10:20 AM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    erdsah88:
    .aspx          could be the default  extension maybe .....
     

    Its more than that, its not recongnizing that the script file is in the views directory, the physical path doesn't even exist if i add .aspx.

     
    As for usage, I really don't need, just stumbled upon it while playing it seemed wrong to me.  Not sure how much rewriting with asp.net effects this, I assume a lot.  I should test an old rewriting solution I had with webforms to see what the results were. 

    Adam Tybor -- abombss.com
  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 10:31 AM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    tgmdbm:
    I'm putting scripts and stylesheets inside the Content folder and including them explicitly... Not ideal.
     

     Coming soon to an mvc contrib near you.

    <!-- Begin Master -->
    <%
    Script.RegisterScriptInclude("defaults");
    %> <html>
    <head></head>
    <body>
    <div>
    <!-- Begin View Page --> <asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
    <%Script.RegisterScriptInclude("~/SomeOtherRootedDir/SomeExtraScriptThatThisPageNeeds.js");%> </asp:Content>
    <!-- End View Page --> </div>
    <%=Script.InstallScripts()%> <!-- End Master --> </body>
    </html>

    It will also handle custom blocks and startup scripts for the particular library you are using. Blocks and startups have keys just like ScriptManager so they can be registered 1000 times and only included once. The only catch thus far is the =InstallScripts need to be at the very bottom of the page, or the Register calls have to be in the constructors and not the view page.

    Adam Tybor -- abombss.com
  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 10:52 AM
    • Loading...
    • shinakuma
    • Joined on 03-01-2003, 4:09 PM
    • Posts 92

    abombss:
    I just noticed today when I was playing around with path's that PhysicalPath does not return the path to the actual view file executing.

    Nor should it. The documentation says PhysicalPath is "The file system path of the current request." According to that, what you are seeing is exactly what I would expect the property to return, a request url translated to file system path.

    Plus, it would be nearly impossible to determine the actual view until the runtime renders it. There's no rule that says About action has to map to About.aspx under the Views folder. What if I have conditional statements that can potentially render 1 of N different views inside the same action? What if I use nvelocity as my view engine for some views? What if my view engine doesn't pull from physical files, but instead from embedded resource or database tables? As you can see, it can't be derived from just the request url.

  • Re: Bug in HttpRequest.PhysicalPath

    01-04-2008, 11:38 AM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    shinakuma:
    "The file system path of the current request."

    What good is it if it doesn't map to a real physical location?

    shinakuma:
    As you can see, it can't be derived from just the request url.

    Right, but that doesn't stop the runtime from setting the physical path of the view or making it null if a physical view file does not exist.

    If what you say is the intended result then thats the dumbest property I have ever seen. I really didn't need it, just stumbled upon it and I am pointing it out.

    There are a lot more things I would rather see fixed/changed than that :)

    Adam Tybor -- abombss.com
  • Re: Bug in HttpRequest.PhysicalPath

    01-09-2008, 3:27 AM
    • Loading...
    • Haacked
    • Joined on 09-17-2003, 2:43 PM
    • Posts 331
    • AspNetTeam

    What scenario are you trying to accomplish that requires the physical path?

    Phil Haack (http://haacked.com/)
    Senior Program Manager, Microsoft

    What wouldn’t you do for a Klondike bar?
  • Re: Bug in HttpRequest.PhysicalPath

    01-09-2008, 4:53 AM
    • Loading...
    • tgmdbm
    • Joined on 12-17-2007, 2:08 PM
    • Posts 805
    • ASPInsiders

    File.Exists( Context.Request.PhysicalPath + ".css" )


    Just as with code behind, I used this in a previous project to dynamically add "Style Behind" and "Script Behind" using ScriptManager and a <head runat="server">

    It was all wired up automatically simply by naming the file the same as the aspx page plus ".css" or ".js" and putting it in the same directory.

  • Re: Bug in HttpRequest.PhysicalPath

    01-13-2008, 4:36 PM
    • Loading...
    • abombss
    • Joined on 06-27-2006, 12:13 PM
    • Chicago, IL
    • Posts 164

    Haacked:
    What scenario are you trying to accomplish that requires the physical path?
     

    Nothing... It just looked strange as I was toying with the framework.

    The only thing I can think of is if you needed to resolve a resource via the physical path relative to the current view.

     

    Adam Tybor -- abombss.com
Page 1 of 1 (10 items)
Microsoft Communities
Page view counter