access js file from another website - asp.net

In IIS, i have a website under which there are various virtual directories. I want to access/link JS file from one virtual directory into another. So, basically i have an application (in virtual dir 1) from which i want to link JS files being used in another application (virtual dir 2). Both these applications are under the same website in IIS.
Also, i am looking at a way of creating a common folder under website from where all applications can link commonly used JS files. Any ideas on how this can be done?

You can add reference like...
<script src="http://www.website.com/foldername/GeneralMethods.js" type="text/javascript"></script>
Get an idea from this thread How to add jQuery in JS file

Related

Where to put ~/Areas/../Views/xxx.cshtml specfic js files in ASP.NET

I am porting a website from MVC4 to ASP.NET Core 3.0
My major views have view specific complex script files which I used to put in the /Areas/AreaName/Scripts/ directory and access them with something like.
I used to put these in a script directory in the area.
<script src="~/Areas/AreaName/Scripts/*ViewName*Scripts.js"></script>
Doing that now results in a fully dedicated file name like
<script src="C:\Users\..\..\..\..\*ViewName*Dripts.js"></script>
Which is clearly not the way to go for obvious reasons.
Do all scripts including view specific scripts now go in the ~/wwwroot/... directory
Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot . The simplest way is create area folders in wwwroot\js , and add area specific js flies into corresponding folder . You can also serve files outside of web root(/wwwroot), see document for code sample .

Using js/css compression frameworks at both asp/aspx files

I have a website which has both asp and aspx pages. Can I use System.Web.Optimization, Combres etc frameworks for both.
Another problem is that these pages doesn't have code-behind as they are generated from the same template at deployment time. Also, I don't have any bin folder at root of website, but at individual virtual directories in IIS. That is, my root of website only has these static asp/aspx files, global.ascx, web.config, css and js files.
So, I can't use something like below because these DLL's doesn't exist at root bin folder:
<%=System.Web.Optimization.Scripts.Render("~/AdminJS.js")%>
<%=Url.CombresLink("AdminJS") %>
A simple solution like <script type='text/javascript' src='/cms/bundling/scripts/admin.js?v=123'></script>
Let me know if more clarity is required.
It shall be great help if I could implement these frameworks.

Setting up application and resource folders in sub virtual application

I am looking to use the below asp.net 4.0 web application structure but not quite sure how to achieve my result as explained below. What configuration will be needed to handle path issues for referencing both. For example ~/css/style.css needs to dig into the WEBSITE. I know I will have to create a helper for RESOURCES -- WebResourcePath("images/image1.jpg") returns full path if that works in a separate virtual directory?
Default Web Site
>SAR-GROUPS
SARGROUPS_WEBSITE
SARGROUPS_RESOURCES
All website files like aspx, js, css, etc. normal web files go in the WEBSITE folder. The RESOURCES folder will contain other files like pdfs, xml, txt, images, and files . These files will not need to be uploaded or updated during deployments and can remain untouched. When I deploy the WEBSITE I only need to delete the WEBSITE folder and copy the new precompiled folder in SAR-GROUPS again. I have to deploy like this as it is automated deployment from scrips that run so this is an xcopy deployment.
Does anyone have good practices or a working setup to achieve this. I am not looking at alternate methods unless it cannot be done or the other way is much better for auto builds.
Thanks
If the files in the SARGROUPS_WEBSITE directory need to reference resources in the SARGROUPS_RESOURCES directory then why not just make the SARGROUPS_RESOURCES virtual directory inside the SARGROUPS_WEBSITE directory? This way you can point the SARGROUPS_RESOURCES virtual directory at a physical location on the disk and delete the contents of SARGROUPS_WEBSITE without touching the resources.
So structure would be
Default Web Site
>SAR-GROUPS
SARGROUPS_WEBSITE
SARGROUPS_RESOURCES
But the physical structure could be anything
You can then reference them like
~/SARGROUPS_RESOURCES/css/style.css
*untested
EDIT
You've totally not understood my answer and/or virtual folders.
Physical structure example:
D:\Inetpub\WEBSITE
D:\Inetpub\RESOURCES
IIS structure:
IIS Root -> Site (that is a website and points to D:\Inetpub\WEBSITE)
IIS Root -> Site > Resources (that is a virtual directory and points to D:\Inetpub\RESOURCES)

How to call WebPage in folder from another WebPage in a folder

I am working in VS2010 ASP.NET, I decided to move some of my pages in folders and they reference pages in other folders. When I run in virtual debug mode in VS it runs ok, but when I deploy it on the host server the pages cannot see each other. i tried using ../FolderName/Webpage.aspx, ~/FolderName/Webpage.aspx and still no avail.
However if I have a webpage that is not in a folder and then reference a page in a folder it works fine. Anyone else have this issue?
The best practice is to use ResolveUrl to reference all resources such as javascript files, css files, etc.
For example:
<script src='<%=ResolveUrl("~/Javascript/datables-extensions.js")%>' type="text/javascript"></script>
As far as pages referencing other pages, you should be able to use the relative path (../Folder/other_page.aspx) without any problems. Don't use absolute paths or your website will have issues like you describe when you deploy to a different environment that has a different folder structure.

asp.net static content in separate project. now how to refer?

Project1.csproj is the website project and StaticContent.csproj is the static content project to hold all .css, .js and image files. I am keeping it separate so that designers can work without touching the main project file and may be use cdn in future. But the problem is how do my .ascx and .aspx pages will refer to these css and js files as that when I run in localhost, it still picks up.
I think the best way is you create a website in IIS for the Static project, and reference it trough something like static.myproject.com (having the appropiate setup) on the other one.
You can still use Webdevserver on Project1.
Is most like what you will have when deploy, and you can put the URL on web.config for easy change

Resources