leora
leora

Reputation: 196489

asp.net mvc - how do i reference an asp file inside the View Directory

i have a page inside my asp..net mvc site. (for some reason it has to be in this directory)

Views/Members/Calendar/admin.asp

i tried going to:

http://www.mySite.com/Views/Members/Calendar/admin.asp

but this doesn't seem to work.

any suggestions on how to have a link to this page?

Upvotes: 1

Views: 288

Answers (3)

eu-ge-ne
eu-ge-ne

Reputation: 28153

ASP.NET MVC blocks all access to any file within the ~/Views directory. If you want to access any file except *.aspx change your ~/Views/web.config to the following: (from Haacked - Security Tip: Blocking Access to ASP.NET MVC Views Using Alternative View Engines):

or remove both <add ... if you want to access *.aspx files too

For IIS 6:

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

For IIS 7:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
        <remove name="BlockViewHandler"/>
        <add name="BlockViewHandler" path="*.aspx" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>

Upvotes: 2

xandy
xandy

Reputation: 27411

View has nothing to do with the actual directory / address, in MVC, controller is the one to deal with this.

Suppose you start with the default template of MVC, the address would be:

http://site.com/CONTROLLER/ACTION/ID

CONTROLLER is the name of the controller class (which under controller directory), ACTION is the method (which return actionresult) within the controller and ID is a string/int that pass as action method parameter.

I think you'd like to have address like:

http://mysite.com/Members/Calendar/admin/

It doesn't really matter where you put the View or controller, but what you should look at is the routing table within the global.asax. Routing mvc tutorial

edit

In the controller, normally you are going to call

return View();

At the end of action. View() is actually an overloaded internal method call of the controlelr class which has 8 different usage. The default without parameter will look for the same view name to the controller. All you need to do in order to reference to different view class other than default, is using: View(IView Class). For example, in your code it might be:

return View(new PROJECT.Members.Calendar.Admin());

Upvotes: 3

Ben Robbins
Ben Robbins

Reputation: 2630

Have you tried adding an IgnoreRoute method to the top of your register routes method that ignores this specific URL? You'll have to edit the web.config in the Views folder to assign this path to the ASP handler because the ~/Views folder gives out 404's by default. The ASP handler should then pick up the request since the MVC handler will ignore it.

Upvotes: 0

Related Questions