Precalculate ASP.NET Embedded WebRessource Url - asp.net

I have the following Problem.
In an Assembly, there are Resources which are exported via "WebRessource" Attribute
Ok. I know that the through the Method GetWebRessourceUrl, I can find out the Ressource Url but this happens basically at Runtime.
I need this Resource Url at Compiletime.
Why?
Because I have a Javascript which calls some of the the WebRessource Urls.
The Tricky Part is, this Javascript is also in a assembly embedded (The same Assembly as the other Resources) and is Generated and embedded at compile Time with the other Ressources.
I am grateful for every help.

Related

Serving extensionless static files in ASP.NET MVC; getting 404s

For whatever reason (ugh, just assume we have to), we have a JavaScript file and a CSS file without an extension in our ASP.NET MVC application. The JavaScript file is at path ~/Scripts/js and the CSS file is at ~/Styles/css. These are static files containing JS and CSS respectively, but without file extensions.
Right now, when I try to load the resources in a browser, I get a 404 for those two paths. What do I need to do to make my ASP.NET MVC application serve these extensionless files (and serve them with the correct MIME types)? Something in the web.config and mapping a particular URL pattern to the HTTP handler for static files, I'm guessing. Apparently my Googling skills are inadequate—forgive me.
I think esmoore68 probably has the best answer... but... if you don't want to do that, I wonder if you could declare the style (and the script) on the page (rather than reference the files), and maybe use labels on the pages where you need these, and actually open the files in code-behind, read them as text, then write them into the labels on the page load?
I haven't tried anything like that, specifically, but it seems like it would work.
If it does, maybe you could create a user control so you can just put that in all the pages, rather than repeating it every time.

Running a copy of a .cshtml file gives a 404

I've created a copy(right-click Copy & Paste) of my Home page in a VS2013 ASP.NET MVC5 project and named it indexL10. When I try to run it, I get the following error:
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make
sure that it is spelled correctly.
Requested URL: /Home/IndexL10
So, I'm guessing there's more to it than copying and pasting. I've tried googling around, but I've not found an answer, or search string that takes me to a page of a user with a similar problem.
Does anyone have any ideas/suggestions? Thanks
*.cshtml files are not like *.aspx files. They're not directly exposed. The URL is translated by the framework into a route. That route points to a particular controller and a particular action in that controller, which is then called by the framework. The action returns an ActionResult, which in MVC is most typically satisfied via a ViewResult. Conventions in the framework come into play to look for a view to render with the same name as the action that was called, but this is not strictly required and can be overridden. Regardless, the view (your *.cshtml file) is rendered by Razor utilizing data provided by the action and returned as a response to the client.

Cannot route static files in ASP.NET WebForms

We have legacy code to maintain and, to solve a specific customer customization problem, we want to route calls to some files to other files. That is, when the app calls a particular ASPX, it will end up hitting another ASPX.
If you call:
www.foo.com/admin/admin.aspx
It will actually hit:
www.foo.com/customizations/customer1/admin/admin.aspx
This is not a good design but this is legacy code. We just want to solve this.
We are using the System.Web.Routing framework to solve it. This works fine when you set RouteExistingFiles to true, except for static files (CSS, JavaScript and Images).
When I first tried it, it retrieved this error:
There is no build provider register for the extension '.css'.
So I did register a build provider in the web.config file for the .css extension. I used this build provider: PageBuilderProvider because someone recommended it in the internet.
It works! But the CSS is being served with text\html content type.
How do I achieve this?
TL;DR: I want to use routes in ASP.NET Web Forms to make a call for a specific CSS file to actually retrieve another one. A customer needs this for customization.
Try coding a HttpHandler. I had to do something similar but for PDF files, I coded a custom HttpHandler in the end - works very well. You can even set the content type in the HttpHandler code and have a pattern matched path the handler will be used for in the web.config. You can also configure it in web.config not to execute if the path does not point to an existing file e.g. so a 404 is returned without having to code that in the handler itself. I can't post my code (VB.NET) ATM because I'm using a tablet but google search for tutorials. You will also probably need to use the TransmitFile function to actually write out the css file. Is it a web forms project or web site? If its a web site there is a special way of registering the HttpHandler in the web.config.

How does people make ASP.NET page in URL with html file name?

I seen an ASP.NET application, in the URL is saying:
http://xxxxxxxxx/FILENAME.html?xxxx=xxx
How come it is html file? But not aspx file? How did they do it?
I heard from my manager that's an ASP.NET project he outsourced.
Sometime I seen people with their web page is ended in .html too, but obviously that is generated dynamically...
Files ending with .html are optional. These are static HTML-pages without any code-behind and can be included as part of any web application. They are not parsed and compiled by the server but rather just sent as good old predefined HTML.
You can also configure the web server so that it routes requests with different endings through the ASP.net rendering engine. This way you can keep the widely recognized ending .html and still have dynamic page generation.
The file extension is not necessarily tied to the execution engine. You can make ASP.NET process .aspx, .html, .htm, .bob, .foobar, .css, etc.
There are multiple of ways to do this:
In IIS manager, set the file extension mapping for .html to point to ASP.NET. If you're using MVC, you can handle this via routing.
Use a rewrite engine to map anything with a .htm* extension to .aspx
There are probably other ways, but these are the most direct.
Also, the .html extension doesn't mean that the file was dynamically generated.
You can use URL rewriting. There are a lot of different rewriters most popular being the URL rewrite module ( http://www.iis.net/download/urlrewrite ) and the built in (in ASP.NET 4.0) Routing Engine ( http://msdn.microsoft.com/en-us/library/cc668201.aspx ).
The URL Rewrite module is external to your application and it translates incoming URLs to regular .aspx URLs. You are responsible for generating the links with .html. It is good if you are adding it to an existing application.
The built in routing can generate urls based on routes and is configured in Global.asax (usually) with code.
Right click on the project.
Add new...
pick the HTML file type.
Some people prefer to use a different extension (or even none at all) in order to hide the technology used to develop the site.
Bear in mind that you would have to properly configure IIS to let the .net engine handle the .html file types.

Defining the Cache Manifest file within ASP.NET

When using a cache manifest file within ASP.NET can I just add a standard text file called something like app.manifest? (which is then referenced from the html in each relevant page).
Or are there other considerations (such as mime type) that demand a more convoluted approach?
In this approach: http://stephenwalther.com/blog/archive/2011/01/26/creating-html5-offline-web-applications-with-asp-net.aspx then Stephen Walther sets up the manifest as a handler. Do I really have to do it that way in ASP.NET, or is there a 'simpler' way in ASP.NET? Just striving for less code!
Thanks.
Well, in sighted article, author has created a custom handler to server the manifest with correct MIME type. This is indeed a good way in ASP.NET where you don't have to touch web server configuration.
If you don't want to write such handler and wish to serve file directly such as "app.manifest" then you have to make sure to modify IIS configuration (for the web-site) map the correct MIME Type (text/cache-manifest) for manifest extension (see this and this for how to register a new MIME type in IIS)

Resources