asp.net mvc - Is it i possible to prevent certain PartialViews from being served if requested directly? -


i'm working on site has routes actions render partial views. lot of these partial views components make complete page.

for instance on search page i'm working on has text box, list of tabs, , table.

seach of these can accessed url similar to

/search/searchpanel /search/tabs/{searchterm} /search/resultstable/searchterm?tab=[currently selected tab] 

and these rendered on renderpartial on index page.

when page loads, display each of these components way want it. @ moment there's nothing stopping user going directly url

/search/tabs 

to render tab control meaningless outside context of rest of elements on page.

is there way me prevent this?

have tried marking controller method private?

private partialviewresult mypartialresultmethod() 

this should allow call within code build pages , disallow public access such through url.

i'm testing make doubly sure answer correct i'll update test.

in tabs example restrict access using second controller method tabs that's private.

so you'd have looks like:

public actionresult tabs(string searchterm) // when search term passed. 

and

private actionresult tabs() // when no search term passed. 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -