Hiding MVC pages in web.config - asp.net

I am taking over an MVC project for which there is no source code. All I have to do is remove all the existing functionalities of the MVC based website leaving just one page alone. Right now, I have decompiled the dll from production and I have a 'not so useful' type of code in my system which needs to be wired up completely.
I am wondering if it's possible to hide all the pages and hyperlinks through web.config just leaving the required page as such? The website looks like below:
I want to keep only the "State Fact Sheets" page removing rest of the pages. is it possible at all to do this in web.config file?

Related

Why can't we use *.cshtml files as custom error pages now that (v4.7) we have "Razor Web Pages"?

B"H
Trying to revamp my global error handling, and running into the mess that is ASP.net error handlers.
I would really like to consolidate my solution as much as possible. So if possible I'd like to use the same pages to display from httpErrors and customErrors. I'd also like to use the appropriate Layout pages if possible. But it seems that if I want to use some kind of dynamic page as a custom error page that it needs to be *.aspx. Why is that? Especially now that we have Razor Web Pages?
PS. This is for an MVC (.net v4.7 ie not asp core) Site
If you are using the .cshtml file as a Razor Web Page, then can't you give the URL of the file, excluding the .cshtml? As per the table here: https://learn.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio
A standalone .cshtml file is will normally depend on a Code behind file (if using Razor Web Pages) or a MVC Controller Action to provide it with its data. I guess this is why you are not allowed to redirect directly to one.

When programming with Razor code extension .cshtml is shown

I am new to web pages.
I made a ASP.Net website(Razor) but here WebSecurity uses cookies and I didn't wanted to use inbuilt features..
Hence I made a new ASP.NET Empty WebSite and then added a Layout page & a content page..
Now when I browse it with in the browser it shows extension .cshtml... This is not the case when I made a ASP.NET website(Razor), they show no extension.
My Question:
Is there a way I can hide .cshtml extension or show .html instead.?
Can I edit WebSecurity default methods like it saves userId in cookies I want to save it in Session..?
Make sure any internal links in your application do not include the file extension. Then the extension will not appear in the browser address bar. If you right-click on an individual file in the File Explorer within WebMatrix and choose "Launch in browser", the extension will be shown, but that shouldn't matter.
If you want to know more about the standard routing behaviour in the Web Pages framework, I wrote an article about it here: http://www.mikesdotnetting.com/Article/165/WebMatrix-URLs-UrlData-and-Routing-for-SEO

add new page to existing website without modifying the rest of the website

i have to add one page to an existing asp.net webforms website.
this will be added at runtime and i'm not allowed to redeploy the entire webapplication / website.
is the (recommended or only) solution to move the code behind code to the aspx file, or do i have other options?
i can't put code in the dll's, and dynamicly runned .cs files are only in the case of a website and not in the case of a webapplication, am i right?
and putting the code from my code behind in de aspx file will always work?
actually as long as their page link to yours via URL you web page doesn't necessary have to be in the same project, unless you're trying to reuse something.
Else technically your project is fine as a standalone and they can just link to yours.
Unless you're worried about the URL then you would have to either use an iframe or some other URL rewrite.
Just for reference: One solution would be to use a dynamic proxy and intercept and extend the existing webapp. Though this approach might be a little too involved for what you're trying to achieve.
LinFu
Castle

ASP.NET webpages without names, like stackoverflow?

Mentioned stackoverflow only as an example, but if you look above the URL for ask is
http://stackoverflow.com/questions/ask
which means /ask is a subdirectory, but they also do this for the specific question pages. How do you code this in .NET?
Not a code question as much as a technique. I know this is great for SEO, but how do you create a site so that every "page" is its own directory? Dynamically.
Do you have a template or a hidden redirect???
How?? :)
It's termed URL rewriting:
Url Rewriting with ASP.NET
MSDN: URL Rewriting in ASP.NET
EDIT: As #Justice points out, StackOverflow uses Routing.
StackOverflow uses something called Routing, which comes with .NET 3.5 SP1. Routing is a popular feature of a number of MVC frameworks, such as ASP.NET MVC, Ruby on Rails, and a number of Python and PHP frameworks.
Stack Overflow was built using ASP.NET MVC which uses a technique called Routing, see:
What Was Stack Overflow Built With?
and Routing
Stack Overflow uses ASP.net MVC
MVC uses the URL + Query String to determine the content, so its not like a URL which points to a specific page, but more like a hierarchical path to the properties of some data to be displayed
E.G. https://stackoverflow.com/users/[Put User ID Here]/[Put User Name Here]
prompts the website to display a USER with an ID specified in the path ( in this case the user name is probably just for kicks ) as opposed to a specific page created just for that user.
I have seen this accomplished by simply creating a folder for every web page and then having each folder contain a Default.aspx document (Assuming Default.aspx is setup as a default document in IIS, which it is by default). Then you can navigate to any folder on the site without specifying the page (Default.aspx).
For the dynamic part, I have worked with CMS systems that do it this way and the Default.aspx page simply inherits from some master template and the CMS system utilizes the ASP.NET rendering enginge to dynamically complete the web page.
Using folders may be a little heavy with the site structure, but it is an easy way to eliminate the page names from the browser.
This is how I structure my website and avoid having to use page names... for example http://www.innovaapps.net/Blog simply brings up the default.aspx page without having to specify the page name.

How to consolidate ASP.NET master pages across applications?

First shot at throwing a question on these boards so hopefully I can get some help, here goes:
I am working to start up the .NET practice at my client. We have 5 small scale .NET applications in place currently with a few them of them live into production. They're mostly small reporting pieces with some data entry/business logic functionality. Each of these applications is currently using the identical master pages.
What I mean is that there is a copy of the same master page in each application. They are all basic website->WCF->BL->DB tiered applications. So I have 4 copies of the same master page that I have to change when I make a change to it.
The client DOES NOT want to consolidate all of these into a single solution. They like the separation of applications across sites. I just don't want to continue dealing with the hassle of multiple updates for common elements (which there will be many more of across these applications).
The code is all stored in team foundation server. We also do NOT want to compile the master page into a .dll and deploy it.
Can anyone please make some suggestions as to how I can maintain a single copy of these common files (master, .css, etc) across my multiple applications.
thanks in advance
You might want to look at Sharing Master Pages in Visual Studio.
If that is no help then you could try using Build Events in Visual Studio. I would pick one of the projects to be my "Main Project" and only edit the master page from that project. When you build the project it would run a command that would copy that master page(if it had changed) to your set locations.
The client DOES NOT want to
consolidate all of these into a single
solution. They like the separation of
applications across sites. I just dont
want to continue dealing with the
hassle of multiple updates for common
elements (which there will be many
more of across these applications).
The code is all stored in team
foundation server. We also do NOT want
to compile the master page into a dll
and deploy it.
You eliminated the only two real options there. What all is in the master page? Would it be possible to extract the HTML UI elements to a single template or series of template HTML files and import those dynamically into the master page? You could then relocate the common HTML to an arbitrary URL and have the master page for each application pull it in dynamically.
Edit: I lied. You could also use a VirtualPathProvider like Sharepoint does to store the master page in a database or some other directory, but beware that VirtualPathProviders do not work in MediumTrust environments.
See:
http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx
If you are using Web Applications (compiled into a dll) rather than Web Sites you can do the following:
Right click on the folder you want to store the master page in
Select "Add Existing Item..."
Browse to the master page on the file system, and select both the .master and the .master.cs files.
Then, rather than clicking on the "Add" button, click on the little down arrow to the right of Add, this will bring up a little menu with the options: "Add" and "Add As Link"
Select "Add As Link" this will reference the file in your project, while leaving it in the original location in your dev environment - this allows you to edit it in either application, while keeping it up to date in the other applications.
Obviously if you edit the code behind, you'll need to re-compile the other projects before you deploy the changes to those sites.
This isn't available in web site projects as they rely on the file structure to work out what is in the project.
EDIT: Missed the css part. Obviously you won't be able to serve those files, so this should only work for the master page.
Don't know your scenario, so
IF you can control the DNS / virtual directories to the applications you could use a format like this:
c:\inetpub\wwwroot\Application1
c:\inetpub\wwwroot\Application2
c:\inetpub\wwwroot\Application3
c:\inetpub\wwwroot\Application4
c:\inetpub\wwwroot\Application5
and have your Master page at c:\inetpub\wwwroot\master.Master,
c:\inetpub\wwwroot\master.Master.cs,
c:\inetpub\wwwroot\master.Master.cs.designer
Then you could reference the single copy of the master page from /../master.Master. I gave this a quick shot with a precompiled master page to make sure I could reach back beyond my root. You might have to give it a shot to see.
We use our source control to create links to the shared files in all the places that we need it. So if you edit in one place, you just need to do a get latest and it will appear in the other places you have linked it.
I ended up going with the VPP route. I created a virtual path provider and built my master page into a DLL and this is working. Now I have a massive problem though in that a Content page whos master page is late bound through the codebehind throws validation/formatting hissy fits because it thinks its should be a stand along page. my CNTRL + K, CNTRL + D has broken on every page where I'm now sharing my master page. This is extremely frustring for me and the team

Resources