Reputation: 1060
How can I determine a given virtual path is within the domain during Application_Start?
// Cross domain virtual path
"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"
// In app domain virtual path
"~/scripts/jquery/1.11.0/jquery.min.js" is not.
Edit :
Can I maybe just use
VirtualPathUtility.IsRelative()
Upvotes: 1
Views: 354
Reputation: 15797
Not sure what you are trying to do, but you could test and see if the file is actually there:
if (File.Exists(Server.MapPath(path)))
{
//file is on the server
}
UPDATE: In response to your question if you can use VirtualPathUtility.IsRelative()
: yes you could. Per MSDN:
Returns a Boolean value indicating whether the specified virtual path is relative to the application.
The difference from what I showed above is File.Exists
will return false if the file doesn't actually exist. VirtualPathUtility.IsRelative()
will return true for a path that is relative, whether a file is there or not.
What you use depends on what you are trying to accomplish, which isn't quite clear.
Upvotes: 2
Reputation: 62093
You can not.
Because there is no path during Application_Start
Application_Start is triggered when the application starts before and page is processed and especially before any HTML is sent.
As incidentally the path you are talking about is and has to be part of the HTML output.... which is in a View.... this is very very very very very very early late in the processing.
For that you ffirst need to identify the view which needs running a control which needs analyzoing and routing a request which needs having a started app - and that last part, is where you want to know the output.
Upvotes: 0