Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 471307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:58:22+00:00 2026-05-12T23:58:22+00:00

I am trying to access a .js file in the views directory. I have

  • 0

I am trying to access a .js file in the views directory.
I have an MVC application with /Views/Home/MyControl.ascx
I have a js file /Views/Home/MyControl.js

I wish to reference the .js file and keep it with the control.
I have tried the following entries in the routing, and none seem to work.

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{file}.js");
        routes.IgnoreRoute("{resource}.js/{*pathInfo}");
        routes.IgnoreRoute("{controller}/{resource}.js/{*pathInfo}");
        routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js(/.*)?" });

Please help, please don’t suggest adding the .js file to the scripts directory.
I would like to make it work this way, or know why it cannot be done.

I would put the script into the page, only script debugging is broken in VS2010 B2.

Thanks
Regards
Craig.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T23:58:22+00:00Added an answer on May 12, 2026 at 11:58 pm

    The Views folder is, well for views, and javascript should be put elsewhere. That’s why the designers of the MVC framework put a web.config in this Views folder that denies access to any file inside. You could modify this defaut setting but be warned that this could be a potential security hole. So open the web.config file located in the Views folder and:

    Replace:

    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    

    with:

    <httpHandlers>
      <add path="*.aspx" verb="*" type="System.Web.HttpNotFoundHandler"/>
      <add path="*.master" verb="*" type="System.Web.HttpNotFoundHandler"/>
      <add path="*.ascx" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    

    Navigate to http://yoursite/Views/test.js

    P.S. You could also remove all the IgnoreRoutes you put in global.asax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access a forms control from a class file in the App_Code
I have a mixed WebForms/MVC application I'm trying to deploy to our staging environment,
I am trying to access a file for xml parsing with this: InputStream inputStream
I'm trying to access a file from one class inside another package inside a
So in C# I am trying to access a file on a network, for
I am trying to access a resource file from a servlet but getting HTTP
I am trying to access an XML file from JSP on my Tomcat server.
i am trying to access a Excel file stored in my Resources and build-embed
I'm trying to access an xml file over http. The address is similar to:
I am trying to access an image file from the drawable folder; directly in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.